-
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.
[#24512] YSQL: Fix incorrect column reference to subplan with OFFSET 0
Summary: There was a bug in our aggregate support implementation. In general, by the execution time column references in the aggregate functions are represented as the position number in the underlying plan's target list. When aggregate is pushed down with the scan, the target list position is translated to the column number of the scanned relation. The Postgres optimizer may modify a column reference multiple times, but in most cases a column reference is initialy represented as the column number of some relation, as relation infos, including column lists, are retrieved by the parser. Later on optimizer removes unused columns from the relation infos, and updates the references accordingly, but the initial number is stores with the reference. Hence we conveniently used it to update the reference when we pushdown. However, there are exceptions. Subqueries are planned independently, and aggregates on subquery results initially refer the targets of the subquery, not columns of some table. In most of the cases it does not create a problem, because we do not push aggregates into subqueries. But sometimes optimizer can figure out that subquery is trivial and flatten it, but references' initial numbers are still point to subquery and therefore update of pushed down column reference is incorrect. This diff no longer relies on the assumption that the initial column number stored with the reference is correct. It pulls the referenced target list entry from the scan and finds there correct column number. Jira: DB-13426 Test Plan: ./yb_build.sh --java-test 'org.yb.pgsql.TestPgRegressFeature#testPgRegressFeature' Reviewers: jason, aagrawal, mtakahara Reviewed By: mtakahara Subscribers: yql Tags: #jenkins-ready Differential Revision: https://phorge.dev.yugabyte.com/D41415
- Loading branch information
1 parent
a5731d6
commit c10148f
Showing
6 changed files
with
46 additions
and
17 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
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