RDB$SQL is a package with utility routines to work with dynamic SQL.
EXPLAINRDB$SQL.EXPLAIN returns tabular information of a query's plan, without executing the query.
Since SQL text generally is multi-line string and have quotes, you may use <alternate string literal>
(strings prefixed by Q) as a way to make escape easy.
Input parameters:
SQL type BLOB SUB_TYPE TEXT CHARACTER SET UTF8 NOT NULL - query statementOutput parameters:
PLAN_LINE type INTEGER NOT NULL - plan's line orderRECORD_SOURCE_ID type BIGINT NOT NULL - record source idPARENT_RECORD_SOURCE_ID type BIGINT - parent record source idLEVEL type INTEGER NOT NULL - indentation level (may have gaps in relation to parent's level)SCHEMA_NAME type RDB$SCHEMA_NAME - schema name of a stored procedurePACKAGE_NAME type RDB$PACKAGE_NAME - package name of a stored procedureOBJECT_NAME type RDB$RELATION_NAME - object (table, procedure) nameALIAS type RDB$SHORT_DESCRIPTION - alias nameRECORD_LENGTH type INTEGER - record length for the record sourceKEY_LENGTH type INTEGER - key length for the record sourceACCESS_PATH type RDB$DESCRIPTION NOT NULL - friendly plan description
select *
from rdb$sql.explain('select * from employee where emp_no = ?');
select *
from rdb$sql.explain(q'{
select *
from (
select full_name name from employee
union all
select customer name from customer
)
where name = ?
}');
PARSE_UNQUALIFIED_NAMESRDB$SQL.PARSE_UNQUALIFIED_NAMES is a selectable procedure that parses a list of unqualified SQL names and returns
one row for each name. The input must follow parse rules for names and the output of unquoted names are uppercased.
select *
from rdb$sql.parse_unqualified_names('schema1, schema2, "schema3", "schema 4", "schema ""5"""');
-- SCHEMA1
-- SCHEMA2
-- schema3
-- "schema 4"
-- "schema "5"