-
Notifications
You must be signed in to change notification settings - Fork 489
Restore contsel/contjoinsel for containment & key-existence operators (#2356) #2417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
crprashant
wants to merge
1
commit into
apache:master
Choose a base branch
from
crprashant:fix/2356-restore-contsel-for-containment
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| /* | ||
| * 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; | ||
| oprname | lhs | rhs | restrict_fn | join_fn | ||
| ---------+--------+--------+-------------+------------- | ||
| <<@ | agtype | agtype | contsel | contjoinsel | ||
| <@ | agtype | agtype | contsel | contjoinsel | ||
| @> | agtype | agtype | contsel | contjoinsel | ||
| @>> | agtype | agtype | contsel | contjoinsel | ||
| (4 rows) | ||
|
|
||
| -- 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; | ||
| oprname | lhs | rhs | restrict_fn | join_fn | ||
| ---------+--------+--------+-------------+------------- | ||
| ? | agtype | agtype | contsel | contjoinsel | ||
| ? | agtype | text | contsel | contjoinsel | ||
| ?& | agtype | agtype | contsel | contjoinsel | ||
| ?& | agtype | text[] | contsel | contjoinsel | ||
| ?| | agtype | agtype | contsel | contjoinsel | ||
| ?| | agtype | text[] | contsel | contjoinsel | ||
| (6 rows) | ||
|
|
||
| -- Scoped guard for issue #2356: assert that none of the specific containment | ||
| -- and key-existence operators on agtype are bound to matchingsel / | ||
| -- matchingjoinsel. We deliberately limit the check to these operator names | ||
| -- (rather than every operator in ag_catalog) so unrelated operators that | ||
| -- legitimately use matchingsel for their own semantics are not affected by | ||
| -- this regression test. | ||
| 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' | ||
| AND o.oprname IN ('@>', '<@', '@>>', '<<@', '?', '?|', '?&') | ||
| AND (o.oprrest::text = 'matchingsel' | ||
| OR o.oprjoin::text = 'matchingjoinsel'); | ||
| leaked_matchingsel_bindings | ||
| ----------------------------- | ||
| 0 | ||
| (1 row) | ||
|
|
||
| -- Smoke test: each operator still works functionally. Selectivity binding | ||
| -- only affects the planner; this guards against an inadvertent operator | ||
| -- removal as part of any future cleanup. | ||
| SELECT '{"a":1,"b":2}'::agtype @> '{"a":1}'::agtype AS contains_yes; | ||
| contains_yes | ||
| -------------- | ||
| t | ||
| (1 row) | ||
|
|
||
| SELECT '{"a":1}'::agtype <@ '{"a":1,"b":2}'::agtype AS contained_yes; | ||
| contained_yes | ||
| --------------- | ||
| t | ||
| (1 row) | ||
|
|
||
| SELECT '{"a":{"b":1}}'::agtype @>> '{"a":{"b":1}}'::agtype AS top_contains_yes; | ||
| top_contains_yes | ||
| ------------------ | ||
| t | ||
| (1 row) | ||
|
|
||
| SELECT '{"a":{"b":1}}'::agtype <<@ '{"a":{"b":1}}'::agtype AS top_contained_yes; | ||
| top_contained_yes | ||
| ------------------- | ||
| t | ||
| (1 row) | ||
|
|
||
| SELECT '{"a":1}'::agtype ? 'a'::text AS exists_text_yes; | ||
| exists_text_yes | ||
| ----------------- | ||
| t | ||
| (1 row) | ||
|
|
||
| SELECT '{"a":1}'::agtype ? '"a"'::agtype AS exists_agtype_yes; | ||
| exists_agtype_yes | ||
| ------------------- | ||
| t | ||
| (1 row) | ||
|
|
||
| SELECT '{"a":1,"b":2}'::agtype ?| ARRAY['a','c'] AS exists_any_text_yes; | ||
| exists_any_text_yes | ||
| --------------------- | ||
| t | ||
| (1 row) | ||
|
|
||
| SELECT '{"a":1,"b":2}'::agtype ?| '["a","c"]'::agtype AS exists_any_agtype_yes; | ||
| exists_any_agtype_yes | ||
| ----------------------- | ||
| t | ||
| (1 row) | ||
|
|
||
| SELECT '{"a":1,"b":2}'::agtype ?& ARRAY['a','b'] AS exists_all_text_yes; | ||
| exists_all_text_yes | ||
| --------------------- | ||
| t | ||
| (1 row) | ||
|
|
||
| SELECT '{"a":1,"b":2}'::agtype ?& '["a","b"]'::agtype AS exists_all_agtype_yes; | ||
| exists_all_agtype_yes | ||
| ----------------------- | ||
| t | ||
| (1 row) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.