From 737d682ee92a396cf32d30f0e95afa6aea84ab52 Mon Sep 17 00:00:00 2001 From: Lindsay Holmwood Date: Fri, 27 Nov 2026 15:59:12 +1100 Subject: [PATCH 1/2] docs(eql): say the JSON GIN index does not serve col <@ needle, and name the v4 ORE operator class The v4 JSON tree page said a GIN index with jsonb_path_ops on eql_v4.json_tree_query(col) serves both containment operators. In PostgreSQL 17 with the v4 bundle, `col @> $1` and `$1 <@ col` use the index, because both inline to jsonb @> with the projection on the left. `col <@ $1` inlines to `$1 @> json_tree_query(col)`, with the projection on the right, and no jsonb GIN operator class serves that, so the query reads every row. The page now says so. The between notes named the ORE btree operator class eql_v4_internal.ore_block_256. The v4 bundle renders the class as eql_v4_internal.ore_block_v2_operator_class, so a user who checks pg_opclass for the old name does not find it. Refs #1968 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01CtEQzxj55RUn35dkbhdwQk --- packages/eql/docs/reference/eql-functions.md | 2 +- packages/eql/docs/reference/json-tree.md | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/eql/docs/reference/eql-functions.md b/packages/eql/docs/reference/eql-functions.md index 103ecffbfd..a3235609b9 100644 --- a/packages/eql/docs/reference/eql-functions.md +++ b/packages/eql/docs/reference/eql-functions.md @@ -166,7 +166,7 @@ SELECT * FROM users WHERE eql_v4.between(age, $1::eql_v4.query_integer_range_ope ``` - `eql_v4.between` is an inlinable SQL function, so the planner sees `ord_term(age) >= lo AND ord_term(age) <= hi`, and a btree on the column's order term serves it as one range scan: `eql_v4.ord_term(col)` for an OPE column (`_ord`, `_ord_ope`, and `_search` for text), `eql_v4.ord_term_ore(col)` for an ORE one (`_ord_ore`, and `_search_ore` for text). -- **An ORE column needs the `eql_v4_internal.ore_block_256` btree operator class**, for its index and so for an ORE range scan. The installer creates that class only when it runs with superuser privileges. Otherwise (on Supabase and other managed roles) it skips it and disables the ORE column domains and the ORE range domains: a value cast to `_ord_ore` or `_search_ore` raises `feature_not_supported`, naming the OPE and equality alternatives, and a value cast to a `query__range_ore` domain raises the same error, naming the family's `_range_ope` domain. On such an install, use an OPE column and its `_range_ope` domain, which need nothing more. +- **An ORE column needs the `eql_v4_internal.ore_block_v2_operator_class` btree operator class**, for its index and so for an ORE range scan. The installer creates that class only when it runs with superuser privileges. Supabase and other managed platforms do not give that privilege. There, the installer skips the class and disables the ORE column domains and the ORE range domains. A value cast to `_ord_ore` or `_search_ore` raises `feature_not_supported`, naming the OPE and equality alternatives. A value cast to a `query__range_ore` domain raises the same error, naming the family's `_range_ope` domain. On such an install, use an OPE column and its `_range_ope` domain. Neither needs the operator class. - Always write it schema-qualified. `BETWEEN` is an SQL keyword, so a bare `between(...)` does not parse. - **Always cast the range parameter to its exact range domain**, as in `$1::eql_v4.query_integer_range_ore`. PostgreSQL resolves a function's domain arguments as their base type, `jsonb`, and every `between` overload takes jsonb domains. So an uncast `$1`, a `jsonb` parameter, or a range of the wrong term (an OPE range on an `_ord_ore` column) or the wrong family matches several overloads, and the statement fails with SQLSTATE 42725 (`function eql_v4.between(...) is not unique`) when it is parsed, before it runs. This differs from the single-bound operators: `col < $1` resolves an untyped `$1`. - A `NULL` range matches no row. So does a range whose low bound is above its high bound, as with SQL `BETWEEN`; the SQL does not reorder the bounds. diff --git a/packages/eql/docs/reference/json-tree.md b/packages/eql/docs/reference/json-tree.md index 9ed303a97e..079a749163 100644 --- a/packages/eql/docs/reference/json-tree.md +++ b/packages/eql/docs/reference/json-tree.md @@ -90,12 +90,18 @@ SELECT id, profile FROM customers WHERE profile <@ $1::eql_v4.query_json; Containment is answered by `jsonb @>` over the projection `eql_v4.json_tree_query(profile)`. A GIN index on that expression serves -both operators: +`profile @> $1`. The index also serves `$1 <@ profile`, the same test +written the other way round: ```sql CREATE INDEX ON customers USING gin ((eql_v4.json_tree_query(profile)) jsonb_path_ops); ``` +No index serves `profile <@ $1`, so that query reads every row. +PostgreSQL runs it as a `jsonb @>` test with +`eql_v4.json_tree_query(profile)` on the right. A GIN index on `jsonb`, with `jsonb_path_ops` or +`jsonb_ops`, serves `@>` only when the indexed value is on the left. + Two containment needles on one array can be answered by different elements. To test several members of one element together, use the element function in the [section below](#one-array-element-and-a-whole-predicate). From 9adcb0f54d4daf41fe35f99c6243981b99a06766 Mon Sep 17 00:00:00 2001 From: Lindsay Holmwood Date: Fri, 27 Nov 2026 16:26:39 +1100 Subject: [PATCH 2/2] docs(eql): type the containment operands and scope the operator class note Write every containment operand in the new json-tree prose with its eql_v4.query_json cast, as the page's own rule requires, and show the index-served $1 <@ col form in the example block. An untyped $1 would resolve to another <@ overload and miss the index. Say that Supabase-like platforms, whose install role cannot create an operator class, skip the ORE class. RDS and Aurora can create it. Refs #1968 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01CtEQzxj55RUn35dkbhdwQk --- packages/eql/docs/reference/eql-functions.md | 2 +- packages/eql/docs/reference/json-tree.md | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/eql/docs/reference/eql-functions.md b/packages/eql/docs/reference/eql-functions.md index a3235609b9..2b5e0f027e 100644 --- a/packages/eql/docs/reference/eql-functions.md +++ b/packages/eql/docs/reference/eql-functions.md @@ -166,7 +166,7 @@ SELECT * FROM users WHERE eql_v4.between(age, $1::eql_v4.query_integer_range_ope ``` - `eql_v4.between` is an inlinable SQL function, so the planner sees `ord_term(age) >= lo AND ord_term(age) <= hi`, and a btree on the column's order term serves it as one range scan: `eql_v4.ord_term(col)` for an OPE column (`_ord`, `_ord_ope`, and `_search` for text), `eql_v4.ord_term_ore(col)` for an ORE one (`_ord_ore`, and `_search_ore` for text). -- **An ORE column needs the `eql_v4_internal.ore_block_v2_operator_class` btree operator class**, for its index and so for an ORE range scan. The installer creates that class only when it runs with superuser privileges. Supabase and other managed platforms do not give that privilege. There, the installer skips the class and disables the ORE column domains and the ORE range domains. A value cast to `_ord_ore` or `_search_ore` raises `feature_not_supported`, naming the OPE and equality alternatives. A value cast to a `query__range_ore` domain raises the same error, naming the family's `_range_ope` domain. On such an install, use an OPE column and its `_range_ope` domain. Neither needs the operator class. +- **An ORE column needs the `eql_v4_internal.ore_block_v2_operator_class` btree operator class**, for its index and so for an ORE range scan. The installer creates that class only when it runs with superuser privileges. Some platforms, such as Supabase, give the install role no way to create an operator class. There, the installer skips the class and disables the ORE column domains and the ORE range domains. A value cast to `_ord_ore` or `_search_ore` raises `feature_not_supported`, naming the OPE and equality alternatives. A value cast to a `query__range_ore` domain raises the same error, naming the family's `_range_ope` domain. On such an install, use an OPE column and its `_range_ope` domain. Neither needs the operator class. - Always write it schema-qualified. `BETWEEN` is an SQL keyword, so a bare `between(...)` does not parse. - **Always cast the range parameter to its exact range domain**, as in `$1::eql_v4.query_integer_range_ore`. PostgreSQL resolves a function's domain arguments as their base type, `jsonb`, and every `between` overload takes jsonb domains. So an uncast `$1`, a `jsonb` parameter, or a range of the wrong term (an OPE range on an `_ord_ore` column) or the wrong family matches several overloads, and the statement fails with SQLSTATE 42725 (`function eql_v4.between(...) is not unique`) when it is parsed, before it runs. This differs from the single-bound operators: `col < $1` resolves an untyped `$1`. - A `NULL` range matches no row. So does a range whose low bound is above its high bound, as with SQL `BETWEEN`; the SQL does not reorder the bounds. diff --git a/packages/eql/docs/reference/json-tree.md b/packages/eql/docs/reference/json-tree.md index 079a749163..18ebdad856 100644 --- a/packages/eql/docs/reference/json-tree.md +++ b/packages/eql/docs/reference/json-tree.md @@ -86,21 +86,24 @@ with `{"name": "Ada"}` at the path. ```sql SELECT id, profile FROM customers WHERE profile @> $1::eql_v4.query_json; SELECT id, profile FROM customers WHERE profile <@ $1::eql_v4.query_json; +SELECT id, profile FROM customers WHERE $1::eql_v4.query_json <@ profile; ``` Containment is answered by `jsonb @>` over the projection `eql_v4.json_tree_query(profile)`. A GIN index on that expression serves -`profile @> $1`. The index also serves `$1 <@ profile`, the same test -written the other way round: +`profile @> $1::eql_v4.query_json`. The index also serves +`$1::eql_v4.query_json <@ profile`, the same test written the other way +round: ```sql CREATE INDEX ON customers USING gin ((eql_v4.json_tree_query(profile)) jsonb_path_ops); ``` -No index serves `profile <@ $1`, so that query reads every row. -PostgreSQL runs it as a `jsonb @>` test with -`eql_v4.json_tree_query(profile)` on the right. A GIN index on `jsonb`, with `jsonb_path_ops` or -`jsonb_ops`, serves `@>` only when the indexed value is on the left. +No index serves `profile <@ $1::eql_v4.query_json`, so that query reads +every row. PostgreSQL runs it as a `jsonb @>` test with +`eql_v4.json_tree_query(profile)` on the right. A GIN index on `jsonb`, +with `jsonb_path_ops` or `jsonb_ops`, serves `@>` only when the indexed +value is on the left. Two containment needles on one array can be answered by different elements. To test several members of one element together, use the element