@@ -160,14 +160,14 @@ pub fn render_functions_file(family_name: &str, domain: &Domain) -> String {
160160 entries. push ( extractor_entry ( term) ) ;
161161 }
162162 for op in OPERATORS {
163- let extractor = Term :: extractor_for_operator ( domain. terms , op. symbol . as_str ( ) ) ;
163+ let term = Term :: term_for_operator ( domain. terms , op. symbol . as_str ( ) ) ;
164164 for sig in op. signatures {
165165 let rendered = sig. render ( & dom) ;
166166 // A `blocker_only` overload (the `@@` jsonpath predicate) always falls
167167 // through to the blocker, even when the domain supports the symbol.
168168 if is_supported ( op. symbol . as_str ( ) ) && !sig. blocker_only {
169- if let Some ( ex ) = extractor {
170- entries. push ( wrapper_entry ( & dom, op, & rendered. left , & rendered. right , ex ) ) ;
169+ if let Some ( t ) = term {
170+ entries. push ( wrapper_entry ( & dom, op, & rendered. left , & rendered. right , t ) ) ;
171171 continue ;
172172 }
173173 }
@@ -275,7 +275,7 @@ pub fn render_query_functions_file(family_name: &str, domain: &Domain) -> String
275275 }
276276 // Comparison wrappers: (storage, query) and its (query, storage) commutator,
277277 // for supported operators only (a query operand is never sent for a blocked
278- // operator). `is_supported(op) ⟹ extractor_for_operator is Some`.
278+ // operator). `is_supported(op) ⟹ term_for_operator is Some`.
279279 //
280280 // Query twins deliberately emit NO blockers (unlike the storage surface). A
281281 // query operand only ever appears as the RHS of `col <op> operand`, and for
@@ -289,21 +289,21 @@ pub fn render_query_functions_file(family_name: &str, domain: &Domain) -> String
289289 if !supported. contains ( & op. symbol . as_str ( ) ) {
290290 continue ;
291291 }
292- let extractor = Term :: extractor_for_operator ( domain. terms , op. symbol . as_str ( ) )
293- . expect ( "a supported operator resolves an extractor " ) ;
292+ let term = Term :: term_for_operator ( domain. terms , op. symbol . as_str ( ) )
293+ . expect ( "a supported operator resolves a term " ) ;
294294 entries. push ( wrapper_entry (
295295 & query_dom,
296296 op,
297297 & storage_dom,
298298 & query_dom,
299- extractor ,
299+ term ,
300300 ) ) ;
301301 entries. push ( wrapper_entry (
302302 & query_dom,
303303 op,
304304 & query_dom,
305305 & storage_dom,
306- extractor ,
306+ term ,
307307 ) ) ;
308308 }
309309
@@ -533,22 +533,6 @@ fn json_entry_cross_blocked_operators(spec: &DomainFamily) -> Vec<&'static str>
533533 . collect ( )
534534}
535535
536- /// The extractor this surface uses on BOTH operands: [`JSON_ENTRY_TERM`]'s own
537- /// (`ord_term` → `ope_cllw`), asked of the `Term` rather than spelled out, so an
538- /// extractor rename stays a single catalog-side change.
539- ///
540- /// Used for every operator rather than resolving per-operator through
541- /// `Term::extractor_for_operator`. That generic rule picks the first capable term
542- /// in the operand's list, so on a dual-term `[Hm, Ope]` operand (text's `_ord`)
543- /// it routes `=`/`<>` through `eq_term` — the per-value HMAC a SteVec scalar leaf
544- /// never carries. That rule is right for a scalar column and wrong for this seam:
545- /// `json_entry` serves exactly one term, so the extractor is a property of the
546- /// SEAM, not of the operator. Since [`json_entry_cross_operators`] already limits
547- /// the emitted set to what this term provides, the pairing is total.
548- fn json_entry_extractor ( ) -> & ' static str {
549- JSON_ENTRY_TERM . extractor ( )
550- }
551-
552536/// Body for a family's json_entry_<T>_functions.sql: comparison
553537/// WRAPPERS binding the fixed `public.eql_v3_json_entry` leaf to the family's
554538/// `_ord` / `_ord_ope` query operands, for every operator json_entry can serve
@@ -576,7 +560,17 @@ pub fn render_json_entry_cross_functions(
576560
577561 let family_name = spec. name ;
578562 let json_entry = json_entry_type ( ) ;
579- let extractor = json_entry_extractor ( ) ;
563+ // The seam's own term on BOTH operands, for every operator — not resolved
564+ // per operator through `Term::term_for_operator`. That generic rule picks the
565+ // first capable term in the operand's list, so on a dual-term `[Hm, Ope]`
566+ // operand (text's `_ord`) it would route `=`/`<>` through `eq_term`, the
567+ // per-value HMAC a SteVec scalar leaf never carries. `json_entry` serves
568+ // exactly one term, so the term is a property of the SEAM, not of the
569+ // operator; [`json_entry_cross_operators`] already limits the emitted set to
570+ // what it provides, so the pairing is total. Passing the `Term` (not an
571+ // extractor name) lets `wrapper_entry` ask the catalog for both the
572+ // extractor and the schema of the body's operator.
573+ let term = JSON_ENTRY_TERM ;
580574 let supported = json_entry_cross_operators ( spec) ;
581575 let blocked = json_entry_cross_blocked_operators ( spec) ;
582576 let mut requires = vec ! [
@@ -607,14 +601,14 @@ pub fn render_json_entry_cross_functions(
607601 op,
608602 & json_entry,
609603 & query_dom,
610- extractor ,
604+ term ,
611605 ) ) ;
612606 entries. push ( wrapper_entry (
613607 & json_entry,
614608 op,
615609 & query_dom,
616610 & json_entry,
617- extractor ,
611+ term ,
618612 ) ) ;
619613 } else if blocked. contains ( & symbol) {
620614 // Both directions, so neither can fall through to `jsonb = jsonb`.
@@ -1152,6 +1146,94 @@ mod tests {
11521146
11531147 use std:: fs;
11541148
1149+ /// Every comparison-wrapper body — scalar, query-twin and json_entry
1150+ /// surfaces, every catalog family — names its operator schema-qualified.
1151+ ///
1152+ /// Wrappers are unpinned `LANGUAGE sql` (to stay inlinable), so their body
1153+ /// is parsed under the CALLER's `search_path`; a bare operator resolves to
1154+ /// whatever that path finds. For the ORE term, whose operators live in
1155+ /// `public`, a caller without `public` on the path got pg_catalog's RECORD
1156+ /// comparison — byte-wise ciphertext order, no error. A bare
1157+ /// operator token anywhere in a wrapper body fails here.
1158+ #[ test]
1159+ fn every_wrapper_body_schema_qualifies_its_operators ( ) {
1160+ let mut bodies = 0 ;
1161+ for family in CATALOG {
1162+ for ( path, sql) in render_type ( family, std:: path:: Path :: new ( "out" ) ) {
1163+ for line in sql
1164+ . lines ( )
1165+ . filter ( |l| l. starts_with ( "AS $$ SELECT eql_v3." ) )
1166+ {
1167+ bodies += 1 ;
1168+ let bare: Vec < & str > = line
1169+ . split_whitespace ( )
1170+ . filter ( |tok| tok. chars ( ) . all ( |c| "<>=@!~#&|-+*/%^" . contains ( c) ) )
1171+ . collect ( ) ;
1172+ assert ! (
1173+ bare. is_empty( ) ,
1174+ "{}: wrapper body uses unqualified operator(s) {bare:?}: {line}" ,
1175+ path. display( )
1176+ ) ;
1177+ // The schema each term's operators actually live in, spelled
1178+ // out here rather than read from `Term::operator_schema`, so a
1179+ // wrong mapping there fails this test for every family. The
1180+ // ORE term compares a composite type whose operators are in
1181+ // `public`; naming pg_catalog there reaches the built-in
1182+ // RECORD comparison, the byte-order bug this guards.
1183+ let want = if line. contains ( "eql_v3.ord_term_ore(" ) {
1184+ " OPERATOR(public."
1185+ } else {
1186+ " OPERATOR(pg_catalog."
1187+ } ;
1188+ assert ! (
1189+ line. contains( want) ,
1190+ "{}: wrapper body does not name its operator as{want}…: {line}" ,
1191+ path. display( )
1192+ ) ;
1193+ let other = if want. contains ( "public" ) {
1194+ " OPERATOR(pg_catalog."
1195+ } else {
1196+ " OPERATOR(public."
1197+ } ;
1198+ assert ! (
1199+ !line. contains( other) ,
1200+ "{}: wrapper body names an operator in the wrong schema: {line}" ,
1201+ path. display( )
1202+ ) ;
1203+ }
1204+ }
1205+ }
1206+ // Wrapper bodies open with an `eql_v3.<extractor>(a)` call (extractor
1207+ // bodies call an `eql_v3_internal` constructor and are skipped). Guards
1208+ // the filter itself: a template change that stopped emitting single-line
1209+ // `AS $$ SELECT eql_v3.` bodies would otherwise pass vacuously.
1210+ assert ! ( bodies > 500 , "only {bodies} wrapper bodies inspected" ) ;
1211+ }
1212+
1213+ /// The `_ord_ore` wrappers compare `eql_v3_internal.ore_block_256` values,
1214+ /// a composite type: only `OPERATOR(public.<op>)` reaches the ORE
1215+ /// comparator. Pins the exact body per operator, on both the storage and
1216+ /// query-twin surfaces (the catalog-wide schema check is
1217+ /// `every_wrapper_body_schema_qualifies_its_operators`).
1218+ #[ test]
1219+ fn ord_ore_wrappers_name_the_public_ore_operators ( ) {
1220+ let s = spec ( "integer" ) ;
1221+ let d = domain ( s, "ord_ore" ) ;
1222+ let storage = render_functions_file ( "integer" , d) ;
1223+ let query = render_query_functions_file ( "integer" , d) ;
1224+ for op in [ "=" , "<>" , "<" , "<=" , ">" , ">=" ] {
1225+ let body = format ! (
1226+ "SELECT eql_v3.ord_term_ore(a) OPERATOR(public.{op}) eql_v3.ord_term_ore(b) $$;"
1227+ ) ;
1228+ assert ! ( storage. contains( & body) , "storage wrapper for {op}: {body}" ) ;
1229+ assert ! ( query. contains( & body) , "query wrapper for {op}: {body}" ) ;
1230+ assert ! (
1231+ !storage. contains( & format!( "eql_v3.ord_term_ore(a) {op} " ) ) ,
1232+ "bare {op} on ORE terms"
1233+ ) ;
1234+ }
1235+ }
1236+
11551237 #[ test]
11561238 fn arg_b_name_is_selector_only_for_path_operators ( ) {
11571239 assert_eq ! ( arg_b_name( "->" ) , "selector" ) ;
@@ -1548,8 +1630,9 @@ mod tests {
15481630 "CREATE FUNCTION eql_v3.matches(a public.eql_v3_text_match, b public.eql_v3_text_match)"
15491631 ) ) ;
15501632 assert ! ( fns. contains(
1551- "SELECT eql_v3.match_term(a) @> eql_v3.match_term(b) \
1552- AND (cardinality(eql_v3.match_term(b)) > 0 OR cardinality(eql_v3.match_term(a)) = 0)"
1633+ "SELECT eql_v3.match_term(a) OPERATOR(pg_catalog.@>) eql_v3.match_term(b) \
1634+ AND (pg_catalog.cardinality(eql_v3.match_term(b)) OPERATOR(pg_catalog.>) 0 \
1635+ OR pg_catalog.cardinality(eql_v3.match_term(a)) OPERATOR(pg_catalog.=) 0)"
15531636 ) ) ;
15541637 // The guarded match wrapper is NOT STRICT: a STRICT SQL function with a
15551638 // non-strict body (the guard's AND/OR) would stop inlining, losing the
@@ -2076,8 +2159,6 @@ mod tests {
20762159 "{excluded} must never reach the extract surface"
20772160 ) ;
20782161 }
2079- // And the extractor is the term's own, not a spelled-out literal.
2080- assert_eq ! ( json_entry_extractor( ) , Term :: Ope . extractor( ) ) ;
20812162 }
20822163
20832164 #[ test]
@@ -2193,7 +2274,7 @@ mod tests {
21932274 assert ! ( sql. contains(
21942275 "CREATE FUNCTION eql_v3.lt(a public.eql_v3_json_entry, b eql_v3.query_integer_ord)"
21952276 ) ) ;
2196- assert ! ( sql. contains( "SELECT eql_v3.ord_term(a) < eql_v3.ord_term(b)" ) ) ;
2277+ assert ! ( sql. contains( "SELECT eql_v3.ord_term(a) OPERATOR(pg_catalog.<) eql_v3.ord_term(b)" ) ) ;
21972278 assert ! ( sql. contains(
21982279 "CREATE FUNCTION eql_v3.lt(a public.eql_v3_json_entry, b eql_v3.query_integer_ord_ope)"
21992280 ) ) ;
@@ -2212,7 +2293,7 @@ mod tests {
22122293 "equality must not be a public wrapper on the extract surface"
22132294 ) ;
22142295 assert ! (
2215- !sql. contains( "SELECT eql_v3.ord_term(a) = eql_v3.ord_term(b)" ) ,
2296+ !sql. contains( "SELECT eql_v3.ord_term(a) OPERATOR(pg_catalog.=) eql_v3.ord_term(b)" ) ,
22162297 "op-equality is gone — equality is document containment, not an extract op"
22172298 ) ;
22182299 // The dropped `_eq` operand never appears, and no hmac equality route
@@ -2299,7 +2380,7 @@ mod tests {
22992380 assert ! ( sql. contains(
23002381 "CREATE FUNCTION eql_v3.lt(a public.eql_v3_json_entry, b eql_v3.query_text_ord)"
23012382 ) ) ;
2302- assert ! ( sql. contains( "SELECT eql_v3.ord_term(a) < eql_v3.ord_term(b)" ) ) ;
2383+ assert ! ( sql. contains( "SELECT eql_v3.ord_term(a) OPERATOR(pg_catalog.<) eql_v3.ord_term(b)" ) ) ;
23032384 assert ! ( sql. contains(
23042385 "CREATE FUNCTION eql_v3.gte(a public.eql_v3_json_entry, b eql_v3.query_text_ord)"
23052386 ) ) ;
@@ -2314,7 +2395,7 @@ mod tests {
23142395 ) ;
23152396 }
23162397 assert ! (
2317- !sql. contains( "SELECT eql_v3.ord_term(a) = eql_v3.ord_term(b)" ) ,
2398+ !sql. contains( "SELECT eql_v3.ord_term(a) OPERATOR(pg_catalog.=) eql_v3.ord_term(b)" ) ,
23182399 "op-equality on text is a FALSE POSITIVE (orderize_string collates)"
23192400 ) ;
23202401
0 commit comments