Skip to main content

Crate rupg_analyze

Crate rupg_analyze 

Source
Expand description

Name resolution, type resolution, the query tree, the rewriter for views and rules.

This crate first ships in milestone M2. See spec/22-crate-layout.md section 22.4 and spec/23-milestones.md.

analyze takes a raw statement of rupg-sql and gives a Query whose expressions have their types, as parse_analyze of PostgreSQL does. The rules of type resolution come from parse_coerce.c, parse_func.c and parse_oper.c of PostgreSQL 19, so a query gets the same functions, the same casts and the same errors.

Modules§

node
The stored form of an expression, which the catalog keeps for a column default, a check constraint and an index expression.
tsdict
The text search dictionaries of the templates simple and snowball: the init functions dsimple_init and dsnowball_init, which read the options of a dictionary, and the lexize functions dsimple_lexize and dsnowball_lexize. CREATE TEXT SEARCH DICTIONARY runs the init function to check the options, as verify_dictoptions does, and ts_lexize runs both. It also has the configurations of lookup_ts_config_cache, with the dictionaries of their maps.
types
The facts of a type that the rules of parse_coerce.c read: the category, the preferred flag, the element type and the array type.

Structs§

Aggref
A call of an aggregate function, as Aggref.
Case
A CASE expression.
Column
A column of a relation.
CopyRelation
The relation of a COPY ... TO and the query that reads its rows.
CopyTarget
The table of a COPY ... FROM, as DoCopy and BeginCopyFrom open it.
Cte
A query of WITH after the analysis, as a CommonTableExpr of the list cteList of a query.
CteRef
The query of WITH that a relation of FROM reads, as a RangeTblEntry of the kind RTE_CTE.
CurrentOf
CurrentOfExpr: the condition of WHERE CURRENT OF on the target table of an UPDATE or a DELETE, which is true for the row that the cursor is on, as execCurrentOf finds it.
CycleClause
CTECycleClause: CYCLE, with the columns that find a cycle, the column of the mark with its two values, and the column of the path.
Deferrable
A DEFERRABLE unique constraint. A write does not fail on a duplicate key of its index: unique_key_recheck checks the key again after the statement, or at the commit when the constraint is deferred.
Defined
The result of define.
Derived
The key of a unique index with an expression or a predicate, which FormIndexDatum computes for each row. A row that does not pass the predicate is not in the index, as ExecInsertIndexTuples checks it with ExecQual. Unique::columns has the places of the key columns in the values of the expressions.
Expr
An expression with its type and its typmod. A typmod of -1 means that the expression has no typmod.
FieldStore
The parts of an assignment to fields of a row value, as FieldStore.
Fill
The default of a new column of ALTER TABLE ... ADD COLUMN, as ATExecAddColumn keeps it in tab->newvals, or the new expression of a generated column of SET EXPRESSION. The rows of the table get this default, also when a later subcommand of the statement sets or drops the default of the column.
Foreign
A foreign key that a write checks after the statement for each row that it wrote, as a trigger of ri_triggers.c checks it. The target table is the referencing table for RI_FKey_check_ins and RI_FKey_check_upd, and the referenced table for the triggers of the actions, such as RI_FKey_noaction_del and RI_FKey_cascade_upd.
Frame
The frame of a window, as the fields frameOptions, startOffset, endOffset, startInRangeFunc, endInRangeFunc, inRangeAsc and inRangeNullsFirst of WindowClause.
FromFunction
A function in FROM, as the functions and funcordinality of a RangeTblEntry of the kind RTE_FUNCTION.
Func
A call of a function.
GroupingFunc
A call of GROUPING, as GroupingFunc. The result has a bit for each argument, with the bit of the last argument as the lowest bit. A bit is 1 when the grouping set of the group does not have the argument.
IsJson
JsonIsPredicate: IS JSON.
Join
A join of two parts of FROM.
JoinRow
The whole row of a join, or of the alias of USING.
JsonBehavior
JsonBehavior: an ON ERROR or an ON EMPTY clause.
JsonCtor
JsonConstructorExpr: a SQL/JSON constructor.
JsonExpr
JsonExpr: JSON_EXISTS, JSON_QUERY or JSON_VALUE.
JsonFormat
JsonFormat: a FORMAT clause.
JsonReturning
JsonReturning: the type of the result of a SQL/JSON function and its format.
JsonTable
TableFunc of the kind TFT_JSON_TABLE: the call of JSON_TABLE.
JsonTableColumn
A column of JSON_TABLE.
JsonTableScan
JsonTablePathScan: a row pattern path and the columns that read its rows.
JsonValue
JsonValueExpr: an input of a SQL/JSON function. The executor reads formatted, and the deparser shows raw and the format.
Merge
The clauses of a MERGE and the foreign keys that its actions check.
MergeClause
MergeAction: a WHEN clause of a MERGE.
MinMax
MinMaxAggInfo: the form of a query whose aggregate calls are each min or max, with a subquery for each aggregate call that reads the first value in the order of its sort operator.
NamedArg
An argument by its name, as NamedArgExpr.
OnConflict
OnConflictExpr: what an INSERT does for a new row with the key of a row that the table has.
OutArg
An argument of CALL for an INOUT or OUT argument of the procedure. A CALL in PL/pgSQL writes the value of the argument back to it, so it must be a variable.
Params
The parameters of a statement.
PartitionCheck
A partition whose rows must satisfy its partition constraint, one entry of tab->partition_constraint.
PermInfo
RTEPermissionInfo: the privileges that the statement needs on a relation.
PlaceHolder
A PlaceHolderVar: the value of expr at the scan or the join of the relations of the subquery, which is null in a row where an outer join above them gives nulls for them, as a column of those relations is.
Product
A statement of the rewrite of a write by the rules of its table, in the order that RewriteQuery gives.
Query
The query tree of a SELECT.
ReindexOptions
The options of REINDEX, as ExecReindex reads them from the option list.
Relation
A relation of FROM, as a RangeTblEntry of the kind RTE_RELATION or RTE_SUBQUERY.
RowCompare
The comparison of two rows with an ordering operator, as RowCompareExpr.
RowMark
A relation that FOR UPDATE or FOR SHARE locks, as a RowMarkClause.
RuleTree
The query trees of a rule, as transformRuleStmt makes them. Each query has the relation of the rule as its first two relations, old and new.
SchemaElements
The elements of CREATE SCHEMA, which the caller runs after the statement made the schema.
Script
The statements of the body of a function in SQL that Body::Statements runs, which fmgr_sql analyzes and runs one after the other, as prepare_next_query and init_execution_state do. A statement can see the changes of the statements before it.
SearchClause
CTESearchClause: SEARCH DEPTH FIRST or SEARCH BREADTH FIRST.
SetOp
An operation of the tree, as SetOperationStmt.
Shown
The list of RETURNING as EXPLAIN shows it in the Output of a ModifyTable. A column of old or new reads RETURNING_OLD or RETURNING_NEW with the number of the column in the table, and merge_action() reads MERGE_ACTION. The other columns are as in the targets of the query.
SortGroup
An item of ORDER BY, GROUP BY, DISTINCT or DISTINCT ON, as SortGroupClause.
SubLink
A subquery in an expression, as SubLink.
Subscript
The parts of a fetch from an array or of an assignment to a part of an array, as SubscriptingRef.
TableSample
TableSampleClause: the sample method of TABLESAMPLE and its arguments.
Target
A column of the result.
TopLevel
A statement that cannot run inside a transaction block or in a function, as PreventInTransactionBlock checks it.
Transform
The expression of USING of ALTER COLUMN ... TYPE for one column, as ATPrepAlterColumnType keeps it in tab->newvals.
Unique
A unique index of the target table, which _bt_check_unique checks for each new version of a row.
Var
A column of a relation of FROM.
Variable
A variable of a function that a query reads as a parameter.
ViewCheck
The WithCheckOption items of the kind WCO_VIEW_CHECK of a write, which ExecWithCheckOptions checks after the write of each row, before RETURNING.
WindowClause
A window of a query, as WindowClause.
WindowFunc
A call of a window function, as WindowFunc.
Write
The table that an INSERT, an UPDATE or a DELETE writes.
XmlExpr
XmlExpr: a SQL/XML function with its own syntax. The type is boolean for IS DOCUMENT, text for XMLSERIALIZE and xml for the others.

Enums§

Action
What a trigger of a foreign key on the referenced table does for an old key, confdeltype and confupdtype.
Body
The body of a function in SQL, as the analyzer reads it for the types of the arguments of a call.
BoolOp
The operators of BoolExpr.
BoolTest
The tests of BooleanTest.
CastForm
CoercionForm of a cast node: the way a cast was written, which a deparse function shows.
Context
CoercionContext: where a cast happens. A cast is allowed in its own context and in each later one.
ExprKind
The kinds of expression.
FrameBound
The start or the end of a frame.
FrameExclusion
The rows that the clause EXCLUDE removes from a frame.
FrameMode
The mode of a frame.
FromItem
A part of FROM: a relation or a join.
FuncForm
The way a call was written, which a deparse function shows.
GroupingSet
A grouping set of GROUP BY, as GroupingSet after transformGroupClause. A simple set names its items by the index of their targets in crate::Query::targets.
JoinKind
The kinds of join. Only the planner makes a semi join or an anti join, as pull_up_sublinks makes them from EXISTS and IN.
JsonBehaviorKind
JsonBehaviorType: what a SQL/JSON function gives on an error or when the path finds no item.
JsonCtorKind
JsonConstructorType: the function of a JsonCtor.
JsonEncoding
JsonEncoding: the ENCODING of a FORMAT JSON clause.
JsonExprOp
JsonExprOp: the function of a JsonExpr.
JsonFormatKind
JsonFormatType: the format of a FORMAT clause.
JsonItemType
JsonValueType: the kind of JSON value that IS JSON accepts.
JsonTablePlan
JsonTablePlan: the plan that gives the rows of JSON_TABLE.
JsonWrapper
JsonWrapper: the WRAPPER clause of JSON_QUERY.
MatchKind
MergeMatchKind: the rows that a WHEN clause takes.
MergeCommand
The action of a WHEN clause.
Message
A message of a statement that defines an object. The client gets the messages before the result.
NullTreatment
The null treatment of a call of a window function, as ignore_nulls.
Path
CoercionPathType: how a cast happens.
RowCompareKind
The comparison of a RowCompare, as rctype.
SetKind
The kinds of set operation.
SetTree
A part of the tree of a set operation.
SqlBody
The body in SQL of a function, as prosqlbody keeps it.
SqlValue
The functions of the SQL standard that take no parentheses.
SubLinkKind
The kinds of SubLink that the analyzer takes.
WriteKind
The kind of a statement that writes the rows of a table, CmdType.
XmlOp
XmlExprOp: the function of an XmlExpr.

Constants§

FRAMEOPTION_END_OFFSET
FRAMEOPTION_END_OFFSET: the end of the frame has an offset.
FRAMEOPTION_END_OFFSET_FOLLOWING
FRAMEOPTION_END_OFFSET_FOLLOWING, which the grammar does not name.
FRAMEOPTION_END_UNBOUNDED_FOLLOWING
FRAMEOPTION_END_UNBOUNDED_FOLLOWING. The grammar makes the bits of the end of a frame with a shift of the bits of the start, so it does not name this bit.
FRAMEOPTION_START_OFFSET
FRAMEOPTION_START_OFFSET: the start of the frame has an offset.
MERGE_ACTION
The relation of merge_action() in Shown::targets, as a MergeSupportFunc.
PG_CATALOG_NAMESPACE
The OID of the schema pg_catalog.
REGRESS_SYMBOLS
The functions of regress.c that have PG_FUNCTION_INFO_V1. A function in C can link to them in the library of the regression tests, and rupg-func runs some of them.
RETURNING_NEW
The relation of a column of the new row in Shown::targets, as a Var with varreturningtype VAR_RETURNING_NEW.
RETURNING_OLD
The relation of a column of the old row in Shown::targets, as a Var with varreturningtype VAR_RETURNING_OLD.
TABLE_OID_ATTNUM
The attribute number of the system column tableoid.

Traits§

Env
The facts of the session that the analyzer reads.
Variables
The variables of a PL/pgSQL function that the queries of the function can name.

Functions§

acl_dependents
The objects with an ACL that names the role other than as their owner, as updateAclDependencies records them in pg_shdepend. The ACL of a column gives an object with the number of the column.
acl_roles
aclmembers: the grantees and the grantors of the texts of an ACL, without PUBLIC, in order and without duplicates.
analyze
parse_analyze: the query tree of a raw statement, which is the stmt of a RawStmt. For a statement of the extended protocol, the Query has the type of each parameter.
analyze_assign
transformPLAssignStmt: analyze_with of the value of an assignment to the variable name of the type ty with the typmod typmod. The value takes the type of the variable with the casts of PL/pgSQL, so that the error of a cast points into the assignment.
analyze_assign_part
transformPLAssignStmt of an assignment to a part of a variable, as x[i] := 5 and r.f[1:2] := a: analyze_with of the PLAssignStmt that rupg_sql::parse_plpgsql_assign gives. The value of the query is the new value of the variable, which is the array with the new value of the element or of the slice.
analyze_product
crate::analyze for a statement of query_rewrite.
analyze_with
crate::analyze of a query of a PL/pgSQL function, whose names can be variables of the function. A name that is a column and a variable is an error, as plpgsql.variable_conflict with the value error gives it.
arg_defaults
stringToNode for the proargdefaults of a function: an expression for each default, in the order of the arguments. A function with no defaults gives no expressions.
attnums
CopyGetAttnums: the indexes of the columns that a list of names gives, or of all the columns when the list is empty. rel is the name of the relation for the error of a column that does not exist.
can_coerce
can_coerce_type: true if each input type has a cast to its target type in the context.
check_outer_joins
The check of make_outerjoininfo: a relation with a row mark cannot be on the nullable side of an outer join, at each level of the query.
column_type
plpgsql_parse_cwordtype: the type and the typmod of the column column of the relation with the qualified name names, or None when the relation or the column does not exist.
copy_filter
The query of the condition WHERE of a COPY ... FROM. The parameter $n is the value of the column n of the row, and the query gives the value of the condition, as ExecQual gives it for the row of CopyFrom.
copy_insert
The INSERT that writes the rows of a COPY ... FROM, as CopyFrom fills a row: the parameter $n is the value of the selected column n, and the other columns get their defaults. defaults is true for a selected column whose field is the marker of DEFAULT. Such a column also gets its default, and the parameters skip it. OVERRIDING SYSTEM VALUE lets the data give a value to an identity column GENERATED ALWAYS, as COPY does.
copy_relation
The checks of DoCopy and BeginCopyTo for the relation of COPY ... TO: table_openrv, CopyGetAttnums and the kind of the relation.
copy_rules_error
The checks of BeginCopyTo on the rewrite of the query of COPY by the rules of its table: the error for a rewrite that is not one statement.
copy_target
The checks of table_openrv and CopyGetAttnums for the relation of COPY.
default_opclass
GetDefaultOpClass: the default operator class of the type for the access method. An exact match comes first. Else the one class that the type has a binary cast to, or the one for a preferred type of its category when there are more.
define
Runs a statement that defines an object, for the role user, and adds the object to the catalog. The statement is the stmt of a RawStmt, and text is its text, which the catalog keeps for a view and for a function.
equality_for_ordering
get_equality_op_for_ordering_op: the = operator of the btree family of an ordering operator, and true when the operator sorts in descending order. None when the operator is not the < or the > of a btree family.
execute_params
EvaluateParams: the query that gives the values of the parameters of EXECUTE. It has no FROM and one column for each expression, which is coerced to the type of its parameter in the assignment context. The caller checks the number of the expressions first.
expand_arguments
expand_function_arguments: the arguments of a call in the order of the function, with the defaults of the arguments that the call does not give. A call with no named argument that gives all the arguments keeps its list.
expand_grouping_sets
expand_grouping_sets: the grouping sets of GROUP BY as lists of items, with the shortest lists first. Each set is the product of the expansions of the items of GROUP BY. With distinct the same set comes once. The result is None when there are more than limit sets.
expand_virtual
expand_virtual_generated_columns: the query with the generation expression of each virtual generated column in the place of each column of the table that the query reads, also in its subqueries and in the queries of its write. The rows of a write keep the null of each virtual generated column of the table.
expand_virtual_body
expand_virtual for the body of a function in SQL.
explicit_cast
coerce_to_target_type with COERCION_EXPLICIT and COERCE_EXPLICIT_CAST for an expression whose type is known, to a type that is not a domain, as the cast $1::text in the body of a SQL function that inline_function puts in a query. None when the type has no such cast.
figure_colname
The name of the column for the expression, or ?column?.
find_library
expand_dynamic_library_name and the stat of internal_load_library: the full name of the library name. The only library that rupg has is the library of the regression tests, by a path that ends in regress or regress.so. A name without a directory is in $libdir, which does not have that library.
find_path
find_coercion_pathway.
first_row_mark
The strength of the first row mark on a table in the query, in its subqueries in FROM and in its views, as the first PlanRowMark of the plan.
foreign_keys
The foreign keys that a write of the kind kind of the table table checks, in the order of the names of their triggers. A leaf partition checks them for its rows of an UPDATE or a DELETE of its partitioned table.
func_cost
procost of the function func, as get_func_cost reads it, or 1 for a function that is not known.
function_body
The body of a function in SQL as the analyzer reads it from the text that the catalog keeps, for a call with arguments of the types inputs, with $1 as the first argument. None when the catalog has no function in SQL with the OID.
function_script
The statements of the body of the function in SQL with the OID, for Body::Statements. None when the catalog has no function in SQL with the OID, or when the body is RETURN.
function_sqlbody
The body in SQL of the function with the OID, as interpret_AS_clause analyzes it for prosqlbody: the arguments have their declared types, and the value of RETURN and the columns of the queries do not take a cast to the result type. None when the catalog has no function in SQL with the OID, or when the function has its body in a string.
is_binary_coercible
IsBinaryCoercible: true if a value of source is a value of target with no change.
is_definition
True for a statement that define runs.
lock_table
LockTableCommand for the role user. The caller does RequireTransactionBlock first. The statement locks each relation after its checks, then the relations that the query of a view reads, or the children of a table without ONLY.
locked_tables
The tables with a row mark in the query, in its subqueries in FROM and in its views.
option_on
True when the boolean option name of reloptions is on, as RelationHasSecurityInvoker and RelationIsSecurityView read security_invoker and security_barrier.
out_columns
build_function_result_tupdesc_t and resolve_polymorphic_tupdesc: the columns of the rows of a call of a function with two or more OUT, INOUT or TABLE parameters, or of a procedure with one or more. A parameter without a name gives the name columnN, and a polymorphic type takes the actual type that the arguments of the call give. None for a function with fewer such parameters.
owned_objects
The objects of a catalog that have a dependency of pg_shdepend on their owner role, as recordDependencyOnOwner makes them. An index, a TOAST table, a composite type as a relation, the row type of a table, an array type and a multirange type have none.
param_types
PrepareQuery: the type OIDs of the parameters that PREPARE declares, as typenameTypeId finds them.
parse_type
parseTypeString: the OID and the typmod of the type that a string names, as the input of regtype and to_regtypemod read it.
plpgsql_cast
get_cast_hashentry: the query SELECT $1 that casts a value of the type source to the type target with the typmod typmod, in the context of PL/pgSQL, where the output and the input functions cast a value when no other cast exists.
query_rewrite
QueryRewrite for a write: the statements of the rewrite by the rules of the target table, in order, or None when no rule fires.
record_fields
get_expr_result_tupdesc and expandRecordVariable: the fields of an expression of type record. A call of a function gives its OUT parameters. The whole row of a join gives the columns of the join. A column of a subquery in FROM gives the fields of its expression in the subquery, also through more subqueries. levels has the relations of the query of the expression, then the relations of each query outside it. None when the fields are not known before the query runs.
reindex_options
The option list of ExecReindex.
relation_by_names
The OID of the relation with the qualified name names, as RangeVarGetRelid finds it with the search path, or None.
relation_row_type
plpgsql_parse_wordrowtype: the row type of the relation with the qualified name names, or None.
resolve_polymorphic
enforce_generic_type_consistency: replaces the polymorphic types in declared with the actual types, and gives the actual result type for result.
rewrite_insert
The INSERT that writes a row of a table again after ALTER COLUMN ... TYPE, as ATRewriteTable evaluates tab->newvals: the parameter $n is the old value of the selected column n, and transforms gives the expression of USING of a selected column, or None for a column that keeps its old value. The expressions refer to the columns by their names, through FROM (VALUES ($1, ...)) AS relname(columns). The other columns get their defaults.
row_type_fields
The name, the type and the typmod of each field of a row type, as build_row_from_rowtype reads them, or None for a type that is not the row type of a relation. A dropped column has no name and the type 0.
rule_tree
The query trees of the rule of the catalog with the OID, from the text of the rule and the search_path that the rule keeps, or None when the catalog has no rule with the OID. pg_get_ruledef shows these queries.
set_constraints
The constraints of a SET CONSTRAINTS: None for ALL, or the OIDs of the deferrable constraints of the names, in the order of the names. A name with no schema finds the constraints with the name in the first schema of search_path that has one.
sort_operators
The < and the > operators of the type, as lookup_type_cache gives lt_opr and gt_opr, or 0 for an operator that the type does not have. get_rule_orderby uses them to show the direction of a sort.
strength_name
LCS_asString.
tablespace_options
transformRelOptions and tablespace_reloptions for CREATE TABLESPACE: the options of the statement, each as name=value, in the order of the statement. An option cannot have a namespace.
temp_namespace
myTempNamespace: the OID of the temporary schema of the session in the catalog, or 0 when the session has none yet.
trigger_when
The condition of WHEN of the trigger of the catalog with the OID, with the query that has old and new as its relations, or None when the catalog has no such trigger or the trigger has no condition. pg_get_triggerdef shows the condition.
vacuum_relations
vacuum for the relations rels of a VacuumStmt, after ExecVacuum has read the options. vacuum is true for VACUUM, and analyze is true for ANALYZE or for VACUUM with the option ANALYZE. The warnings for the relations that the statement skips go to warnings, also when a later relation gives an error.
view_query
The query of a view or of a materialized view of the catalog, from the text of the view and the search_path that the view keeps, or None when the catalog has no view with the OID. pg_get_viewdef shows this query.

Type Aliases§

Allowed
The privilege check of LOCK TABLE. allowed(relid, role) is LockTableAclCheck for the mode of the statement: true when the role can lock the relation.
Take
The lock of LOCK TABLE on one relation. take(relid) is LockRelationOid in the mode of the statement, or ConditionalLockRelationOid with NOWAIT. It gives false when the lock is not free and the statement has NOWAIT.