-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#22923] YSQL: In EXPLAIN command, fix relids of prefix keys when und…
…er a subquery distinct index scan. Summary: ### Issue Schema ``` create table demo(k int, x int, v int, a int, d date, primary key(k,x,v,d)); ``` Query ``` explain select v from (select distinct on (v) v from demo where k=1 and x=1) foo; ``` returns an error ``` ERROR: invalid attnum 2 for relation "foo" ``` ### Root Cause The relation index in index target list (var->varno) is relative to the subquery. That is, var->varno indexes into PlannerInfo's RangeTable. In explain, we require a global index across all RangeTableEntries. That is, we need an index into PlannerGlobal's RangeTable instead. ### Fix We can access the index into PlannerGlobal's RangeTable by looking at scanrelid of the IndexScan. In this revision, we adjust the varno's of the index expressions to this scanrelid. Jira: DB-11842 Test Plan: Jenkins Added a test case to yb_distinct_pushdown_base.sql to guard against regression for the above scenario. ``` ./yb_build.sh --java-test TestPgRegressDistinctPushdown ``` Backport-through: 2.20 Reviewers: tnayak, smishra Reviewed By: tnayak Subscribers: yql Differential Revision: https://phorge.dev.yugabyte.com/D36181
- Loading branch information
Showing
3 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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