Documentation
¶
Overview ¶
Package normalize ports pg_query_normalize.c at the pinned 18.0.0: constants in the query text are replaced with $n parameter references, numbered in tree-walk order after the highest existing $n.
The walk is const_record_walker: a hand-written switch over the raw parse tree with special cases for constant-bearing utility statements and for SELECT (GROUP BY entries are matched against target-list entries by fingerprint so both get the same parameter numbers), falling through to PostgreSQL 18's raw_expression_tree_walker for everything else. Node types that walker does not know abort the walk of that subtree — upstream's elog(ERROR) is caught per-node and swallowed — which this port reproduces by returning early for unsupported types (walker.go).
pg_qsort (src/port/qsort.c via lib/sort_template.h): the Bentley & McIlroy quicksort PostgreSQL uses. fill_in_constant_lengths sorts the constant records with it, and the sort is not stable — for duplicate locations (a MultiAssignRef source walked once per target column), WHICH duplicate ends up first decides the parameter number the constant gets (e.g. "SET (c,b,a) = ($1, b+$4, DEFAULT)"). Byte-parity therefore needs the exact algorithm, not just the same ordering criterion.
raw_expression_tree_walker (src/backend/nodes/nodeFuncs.c, PostgreSQL 18) ported over the protobuf tree. Every WALK(child) goes back through state.walk, so the const_record_walker interceptions (A_Const, ParamRef, TypeName, SelectStmt, DefElem, …) apply at every level, exactly as the C callback does.
Node types missing from the switch are the ones raw_expression_tree_walker elogs about; pg_query_normalize.c catches that error per-node and stops walking the subtree, so here they simply return false.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
This section is empty.