crprashant commented on code in PR #2417:
URL: https://github.com/apache/age/pull/2417#discussion_r3183951989
##########
regress/expected/cypher_match.out:
##########
@@ -2407,15 +2407,15 @@ SELECT * FROM cypher('cypher_match', $$ MATCH (a
{name:a.name}) MATCH (a {age:a.
SELECT * FROM cypher('cypher_match', $$ MATCH p=(a)-[u {relationship:
u.relationship}]->(b) RETURN p $$) as (a agtype);
a
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- [{"id": 281474976710661, "label": "", "properties": {"age": 4, "name":
"T"}}::vertex, {"id": 4785074604081153, "label": "knows", "end_id":
281474976710666, "start_id": 281474976710661, "properties": {"years": 3,
"relationship": "friends"}}::edge, {"id": 281474976710666, "label": "",
"properties": {"age": 6}}::vertex]::path
[{"id": 281474976710659, "label": "", "properties": {"age": 3, "name":
"orphan"}}::vertex, {"id": 4785074604081154, "label": "knows", "end_id":
281474976710666, "start_id": 281474976710659, "properties": {"years": 4,
"relationship": "enemies"}}::edge, {"id": 281474976710666, "label": "",
"properties": {"age": 6}}::vertex]::path
+ [{"id": 281474976710661, "label": "", "properties": {"age": 4, "name":
"T"}}::vertex, {"id": 4785074604081153, "label": "knows", "end_id":
281474976710666, "start_id": 281474976710661, "properties": {"years": 3,
"relationship": "friends"}}::edge, {"id": 281474976710666, "label": "",
"properties": {"age": 6}}::vertex]::path
(2 rows)
Review Comment:
Good catch — addressed in `bff7be66`. Added `RETURN p ORDER BY id(u)` to all
three `MATCH p=(a)-[u {...}]->(b)` queries in the *self-referencing property
constraints (issue #898)* block of `regress/sql/cypher_match.sql` (lines ~1067,
~1070, ~1073). Expected output regenerated; the result set is unchanged, but
the order is now deterministic across PG/AGE planner versions instead of being
encoded incidentally in the .out file.
##########
regress/expected/cypher_vle.out:
##########
@@ -726,8 +726,8 @@ SELECT prepend_node('list01', 'b');
SELECT * FROM show_list_use_vle('list01');
node
-----------------------------------------------------------------------------------
- {"id": 1407374883553282, "label": "node", "properties": {"content":
"b"}}::vertex
{"id": 1407374883553281, "label": "node", "properties": {"content":
"a"}}::vertex
+ {"id": 1407374883553282, "label": "node", "properties": {"content":
"b"}}::vertex
(2 rows)
Review Comment:
Agreed — fixed in `bff7be66`. Added `ORDER BY id(v)` to the `MATCH (h:head
{name: $list_name})-[e:next*]->(v:node) RETURN v` Cypher inside
`show_list_use_vle` (`regress/sql/cypher_vle.sql`). The 2-row and 3-row results
are now ordered by stable vertex id (insertion order ascending), which is
independent of plan choice.
##########
regress/sql/containment_selectivity.sql:
##########
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * Regression coverage for issue #2356:
+ * The containment (@>, <@, @>>, <<@) and key-existence (?, ?|, ?&)
+ * operators on agtype must be bound to the lightweight selectivity
+ * helpers contsel / contjoinsel during planning. Earlier PG14+
+ * branches used matchingsel / matchingjoinsel, which caused planning
+ * to invoke agtype_contains() against pg_statistic MCVs and produced
+ * a 30%+ planning-time regression on point queries (severe TPS drop
+ * reported on the PG18 branch).
+ *
+ * This test pins the bindings by querying pg_operator directly. If
+ * someone re-introduces matchingsel here, the test diff is loud and
+ * precise.
+ */
+
+LOAD 'age';
+SET search_path TO ag_catalog;
+
+-- Selectivity helpers for the four containment operators.
+SELECT o.oprname,
+ pg_catalog.format_type(o.oprleft, NULL) AS lhs,
+ pg_catalog.format_type(o.oprright, NULL) AS rhs,
+ o.oprrest::text AS restrict_fn,
+ o.oprjoin::text AS join_fn
+FROM pg_catalog.pg_operator o
+JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace
+WHERE n.nspname = 'ag_catalog'
+ AND o.oprname IN ('@>', '<@', '@>>', '<<@')
+ORDER BY o.oprname, lhs, rhs;
+
+-- Selectivity helpers for all key-existence operator overloads
+-- (right-hand side may be text, text[], or agtype).
+SELECT o.oprname,
+ pg_catalog.format_type(o.oprleft, NULL) AS lhs,
+ pg_catalog.format_type(o.oprright, NULL) AS rhs,
+ o.oprrest::text AS restrict_fn,
+ o.oprjoin::text AS join_fn
+FROM pg_catalog.pg_operator o
+JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace
+WHERE n.nspname = 'ag_catalog'
+ AND o.oprname IN ('?', '?|', '?&')
+ORDER BY o.oprname, lhs, rhs;
+
+-- A single aggregate guard: there must be NO operator in ag_catalog whose
+-- selectivity is still bound to matchingsel / matchingjoinsel. This is the
+-- catch-all that keeps issue #2356 from silently regressing if a future
+-- operator is added.
+SELECT COUNT(*) AS leaked_matchingsel_bindings
+FROM pg_catalog.pg_operator o
+JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace
+WHERE n.nspname = 'ag_catalog'
Review Comment:
Fair point — scoped in `bff7be66`. The aggregate guard now restricts the
check to the seven operator names that issue #2356 covers (`@>`, `<@`, `@>>`,
`<<@`, `?`, `?|`, `?&`) instead of every operator in `ag_catalog`. So a future
operator that legitimately uses `matchingsel` for its own semantics will not
flag this regression test, but any of the 10 containment / key-existence
overloads silently sliding back to `matchingsel` / `matchingjoinsel` will.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]