Skip to content

Support correlated subquery in UPDATE assignments (SET)#8286

Merged
Praveen2112 merged 9 commits intotrinodb:masterfrom
Praveen2112:praveen/010_2/set_correlated_queries
Oct 8, 2021
Merged

Support correlated subquery in UPDATE assignments (SET)#8286
Praveen2112 merged 9 commits intotrinodb:masterfrom
Praveen2112:praveen/010_2/set_correlated_queries

Conversation

@Praveen2112
Copy link
Member

@Praveen2112 Praveen2112 commented Jun 16, 2021

Additionally we support MarkDistinct and AssignUniqueId for Update node. It works only for broadcast join and there will be a follow up PR that flips the Join to BROADCAST like we do join SemiJoinNode in Delete operation

@cla-bot cla-bot bot added the cla-signed label Jun 16, 2021
@Praveen2112 Praveen2112 force-pushed the praveen/010_2/set_correlated_queries branch 4 times, most recently from 68af1d5 to 836ba76 Compare June 16, 2021 13:12
Copy link
Member Author

Choose a reason for hiding this comment

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

We could merge it with the previous tests but for HDP 3.1 it throws an IO Excpetion (https://issues.apache.org/jira/browse/HIVE-22318)

Happy to apply a workaround for it

cc: @losipiuk

Copy link
Member

Choose a reason for hiding this comment

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

We could merge it with the previous tests but for HDP 3.1 it throws an IO Excpetion

is the test run for any other Hive version than 3?

Copy link
Member

Choose a reason for hiding this comment

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

Please merge the test back, so that it's easier to see changes.

see // TODO (https://github.com/trinodb/trino/issues/8268) for the problem you're hitting.

@Praveen2112 Praveen2112 force-pushed the praveen/010_2/set_correlated_queries branch from 836ba76 to 604e777 Compare June 16, 2021 14:23
@Praveen2112 Praveen2112 marked this pull request as ready for review June 16, 2021 14:23
Copy link
Member

Choose a reason for hiding this comment

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

Please merge the test back, so that it's easier to see changes.

see // TODO (https://github.com/trinodb/trino/issues/8268) for the problem you're hitting.

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I would love to see in the commit description why this check is no longer needed :)

Copy link
Member

Choose a reason for hiding this comment

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

👍 Why this check is removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Now with support for correlated queries for assignment...we would translate them to a LEFT JOIN with a non SCALAR build source.

Copy link
Member

Choose a reason for hiding this comment

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

moved to top level discussion @ #8286 (comment)

@findepi findepi requested review from dain, electrum and sopel39 June 16, 2021 15:06
@Praveen2112 Praveen2112 force-pushed the praveen/010_2/set_correlated_queries branch from fb737bc to 4055b11 Compare June 17, 2021 11:44
@findepi
Copy link
Member

findepi commented Jun 17, 2021

@sopel39 can you take a look at property derivations?

@sopel39
Copy link
Member

sopel39 commented Jun 17, 2021

@sopel39 can you take a look at property derivations?

These look good

Comment on lines 1418 to 1421
Copy link
Member

Choose a reason for hiding this comment

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

Any particular reason to move this test case around?
Please keep it here for smaller diff

Copy link
Member

Choose a reason for hiding this comment

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

bump

Copy link
Member

Choose a reason for hiding this comment

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

Add a comment hinting why this test case is interesting

Copy link
Member Author

Choose a reason for hiding this comment

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

There is a comment above which specifies the interesting reason for it.

Copy link
Member

Choose a reason for hiding this comment

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

i see a blank line above this query, which comment are you referring to?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was referring the comment in Line 1420.

@Praveen2112 Praveen2112 force-pushed the praveen/010_2/set_correlated_queries branch from 4055b11 to 73e3911 Compare June 21, 2021 10:45
@Praveen2112 Praveen2112 changed the title Support correlated subquery in UPDATE SET Support correlated subquery in UPDATE assignments (SET) Jun 21, 2021
Copy link
Member

Choose a reason for hiding this comment

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

👍 Why this check is removed?

@findepi
Copy link
Member

findepi commented Jun 21, 2021

@Praveen2112 do you consider this still a WIP?

@Praveen2112 Praveen2112 removed the WIP label Jun 21, 2021
@Praveen2112 Praveen2112 force-pushed the praveen/010_2/set_correlated_queries branch from 6125f3c to 8d471a6 Compare October 4, 2021 13:46
@Praveen2112
Copy link
Member Author

@martint AC

@Praveen2112 Praveen2112 force-pushed the praveen/010_2/set_correlated_queries branch from 8d471a6 to 003984f Compare October 5, 2021 09:32
This would remove the Analysis#resetUpdateType as the update type should never even be
set to Update/delete for explain analyze queries
This makes the check if a table is update target or not independent on current state of the update type.
@Praveen2112 Praveen2112 force-pushed the praveen/010_2/set_correlated_queries branch from 003984f to b2173e0 Compare October 6, 2021 10:19
@Praveen2112
Copy link
Member Author

@martint AC

@Praveen2112 Praveen2112 force-pushed the praveen/010_2/set_correlated_queries branch from b2173e0 to 93e9caf Compare October 7, 2021 06:44
@findepi findepi added the enhancement New feature or request label Oct 7, 2021
Copy link
Member

Choose a reason for hiding this comment

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

This is used when creating a TableScanNode to set the updateTarget flag. Is it intentional that after this change we set the flag to true for ANALYZE, CREATE MATERIALIZED VIEW etc., while before this change it was set only for UPDATE and DELETE queries?

Copy link
Member Author

Choose a reason for hiding this comment

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

It will be still set only for UPDATE and DELETE queries - as targetTable is set only for those two types of queries and isUpdateTarget will return false if the targetTable is Optional#empty

Copy link
Member

Choose a reason for hiding this comment

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

Right.

Optimizer could flip the join and we don't want to apply the delete/update for incorrect table.
When we pass a correlated query as an assignment to a column we would
translate them to a LEFT JOIN with a non SCALAR build source so current
restriction is removed.
@Praveen2112 Praveen2112 force-pushed the praveen/010_2/set_correlated_queries branch from 93e9caf to 06b408d Compare October 8, 2021 08:48
@Praveen2112
Copy link
Member Author

@kasiafi Thanks for the review. AC

@Praveen2112 Praveen2112 merged commit a72a739 into trinodb:master Oct 8, 2021
@github-actions github-actions bot added this to the 364 milestone Oct 8, 2021
@Praveen2112 Praveen2112 mentioned this pull request Oct 18, 2021
12 tasks
@findepi findepi mentioned this pull request Nov 25, 2021
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed enhancement New feature or request

Development

Successfully merging this pull request may close these issues.

7 participants