Skip to content
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

Fix join alias resolution #2733

Merged
merged 1 commit into from Jun 13, 2019
Merged

Fix join alias resolution #2733

merged 1 commit into from Jun 13, 2019

Conversation

serprex
Copy link
Member

@serprex serprex commented May 24, 2019

Fixes #2642

FROM (query) alias ignored renaming
In nested subqueries the select list would rename, while the join alias would not respect that

DESCRIPTION: fix error caused by joins with shadowed aliases

@codecov
Copy link

codecov bot commented May 24, 2019

Codecov Report

Merging #2733 into master will increase coverage by 0.86%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #2733      +/-   ##
==========================================
+ Coverage   91.28%   92.14%   +0.86%     
==========================================
  Files         127      127              
  Lines       30492    30470      -22     
==========================================
+ Hits        27835    28078     +243     
+ Misses       2657     2392     -265

@serprex serprex force-pushed the fix_2642_joinalias branch 3 times, most recently from 7b7b8b8 to 10bdcc8 Compare May 25, 2019 00:02
@serprex serprex requested a review from onderkalaci May 28, 2019 17:24
src/backend/distributed/utils/ruleutils_11.c Outdated Show resolved Hide resolved
src/test/regress/sql/multi_name_nested.sql Outdated Show resolved Hide resolved
src/test/regress/sql/multi_name_nested.sql Outdated Show resolved Hide resolved
@serprex serprex force-pushed the fix_2642_joinalias branch 6 times, most recently from 9b0fd0b to 250b744 Compare May 30, 2019 23:58
@serprex
Copy link
Member Author

serprex commented Jun 3, 2019

I've confirmed this is an upstream bug

postgres=# create table events_table (id integer primary key, user_id integer);
CREATE TABLE
postgres=# create table users_table_ref (id integer primary key, value_2 integer);
CREATE TABLE
postgres=# create view asdf as SELECT r
FROM
  (SELECT  user_id_deep, random() as r -- prevent pulling up the subquery
   FROM (events_table
         INNER JOIN
         users_table_ref ON (events_table.user_id = users_table_ref.value_2)) AS join_alias(user_id_dee
p)) AS bar,
     (events_table
      INNER JOIN
     users_table_ref ON (events_table.user_id = users_table_ref.value_2)) AS join_alias(user_id_deep)
WHERE (bar.user_id_deep = join_alias.user_id_deep);
CREATE VIEW
postgres=# \d+ asdf
                                 View "public.asdf"
 Column |       Type       | Collation | Nullable | Default | Storage | Description 
--------+------------------+-----------+----------+---------+---------+-------------
 r      | double precision |           |          |         | plain   | View definition:
 SELECT bar.r
   FROM ( SELECT join_alias_1.user_id_deep,
            random() AS r
           FROM (events_table events_table_1
             JOIN users_table_ref users_table_ref_1 ON events_table_1.user_id = users_table_ref_1.value_2) join_alias(user_id_deep, user_id, id, value_2)) bar,
    (events_table
     JOIN users_table_ref ON events_table.user_id = users_table_ref.value_2) join_alias(user_id_deep, user_id, id, value_2)
  WHERE bar.user_id_deep = join_alias.user_id_deep;

& confirmed that my one liner fix fixes this

Copy link
Member

@marcocitus marcocitus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe wait 1-2 days before merging to see if pgsql-hackers responds with an alternative suggestion, but otherwise seems fine.

@serprex
Copy link
Member Author

serprex commented Jun 13, 2019

Postgres has committed this fix to their ruleutils

Updating branch to match Tom's commit

FROM (query) alias ignored renaming
In nested subqueries the select list would rename, while the join alias would not respect that
@citusdata citusdata deleted a comment from codecov bot Jun 13, 2019
@citusdata citusdata deleted a comment from codecov bot Jun 13, 2019
@citusdata citusdata deleted a comment from codecov bot Jun 13, 2019
@serprex serprex merged commit ab15a21 into master Jun 13, 2019
@onderkalaci
Copy link
Member

Postgres has committed this fix to their ruleutils
Updating branch to match Tom's commit

Great!

@serprex serprex deleted the fix_2642_joinalias branch June 27, 2019 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Two join aliases with the same name fails to deparse accurately
4 participants