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

Add exchange for union with TableScan and Values #207

Merged
merged 3 commits into from Feb 12, 2019

Conversation

sopel39
Copy link
Member

@sopel39 sopel39 commented Feb 11, 2019

Extracted-From: prestodb/presto#11957

@sopel39 sopel39 requested a review from findepi February 11, 2019 11:48
@cla-bot
Copy link

cla-bot bot commented Feb 11, 2019

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to cla@prestosql.io. If you are contributing on behalf of someone else (e.g., your employer), the individual CLA may not be sufficient and your employer may need the Corporate CLA signed.


/**
* These are plan tests similar to what we have for other optimizers (e.g. {@link io.prestosql.sql.planner.TestPredicatePushdown})
* They test that the plan for a query after the optimizer runs is as expected.
Copy link
Member

Choose a reason for hiding this comment

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

The above 2 lines are useless, i would remove the whole javadoc

* These are separate from {@link TestAddExchanges} because those are unit tests for
* how layouts get chosen.
*/
public class TestAddExchangesPlans
Copy link
Member

Choose a reason for hiding this comment

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

Why is it separate from TestLogicalPlanner?

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 think they are mean to test that specific code in AddExchanges triggers, which is fine by me.

@sopel39
Copy link
Member Author

sopel39 commented Feb 12, 2019

I've reviewed the original code, landing

This prevents queries like SELECT nationkey FROM nation UNION SELECT 1
from executing on a single node.

Plan before change:

Fragment 0 [SINGLE]
     Output layout: [nationkey_4]
     Output partitioning: SINGLE []
     Grouped Execution: false
     - Output[nationkey] => [nationkey_4:bigint]
             nationkey := nationkey_4
         - Aggregate(FINAL)[nationkey_4] => [nationkey_4:bigint]
             - LocalExchange[HASH][$hashvalue] ("nationkey_4") => nationkey_4:bigint, $hashvalue:bigint
                 - Project[] => [nationkey_4:bigint, $hashvalue_9:bigint]
                         $hashvalue_9 := "combine_hash"(bigint '0', COALESCE("$operator$hash_code"("nationkey_4"), 0))
                     - Project[] => [nationkey_4:bigint, $hashvalue_7:bigint]
                             nationkey_4 := "nationkey"
                         - RemoteSource[1] => [nationkey:bigint, $hashvalue_7:bigint]
                 - Project[] => [nationkey_4:bigint, $hashvalue_11:bigint]
                         $hashvalue_11 := "combine_hash"(bigint '0', COALESCE("$operator$hash_code"("nationkey_4"), 0))
                     - Project[] => [nationkey_4:bigint, $hashvalue_10:bigint]
                             nationkey_4 := "expr_3"
                             $hashvalue_10 := "combine_hash"(bigint '0', COALESCE("$operator$hash_code"("expr_3"), 0))
                         - Aggregate(PARTIAL)[expr_3] => [expr_3:bigint]
                             - Project[] => [expr_3:bigint]
                                     Cost: {rows: 1 (9B), cpu: 9.00, memory: 0.00, network: 0.00}
                                     expr_3 := BIGINT '1'
                                 - LocalExchange[ROUND_ROBIN] () =>
                                         Cost: {rows: 1 (0B), cpu: 0.00, memory: 0.00, network: 0.00}
                                     - Values => []
                                             Cost: {rows: 1 (0B), cpu: 0.00, memory: 0.00, network: 0.00}
                                             ()

 Fragment 1 [SOURCE]
     Output layout: [nationkey, $hashvalue_8]
     Output partitioning: SINGLE []
     Grouped Execution: false
     - Project[] => [nationkey:bigint, $hashvalue_8:bigint]
             $hashvalue_8 := "combine_hash"(bigint '0', COALESCE("$operator$hash_code"("nationkey"), 0))
         - Aggregate(PARTIAL)[nationkey] => [nationkey:bigint]
             - TableScan[tpch:tpch:nation:sf1.0, grouped = false] => [nationkey:bigint]
                     Cost: {rows: 25 (225B), cpu: 225.00, memory: 0.00, network: 0.00}
                     nationkey := tpch:nationkey

Plan after change:
 Fragment 0 [SINGLE]
     Output layout: [nationkey_4]
     Output partitioning: SINGLE []
     Grouped Execution: false
     - Output[nationkey] => [nationkey_4:bigint]
             nationkey := nationkey_4
         - RemoteSource[1] => [nationkey_4:bigint]

 Fragment 1 [HASH]
     Output layout: [nationkey_4]
     Output partitioning: SINGLE []
     Grouped Execution: false
     - Aggregate(FINAL)[nationkey_4] => [nationkey_4:bigint]
         - LocalExchange[HASH][$hashvalue] ("nationkey_4") => nationkey_4:bigint, $hashvalue:bigint
             - Project[] => [nationkey_4:bigint, $hashvalue_9:bigint]
                     $hashvalue_9 := "combine_hash"(bigint '0', COALESCE("$operator$hash_code"("nationkey_4"), 0))
                 - Project[] => [nationkey_4:bigint, $hashvalue_7:bigint]
                         nationkey_4 := "nationkey"
                     - RemoteSource[2] => [nationkey:bigint, $hashvalue_7:bigint]
             - Project[] => [nationkey_4:bigint, $hashvalue_12:bigint]
                     $hashvalue_12 := "combine_hash"(bigint '0', COALESCE("$operator$hash_code"("nationkey_4"), 0))
                 - Project[] => [nationkey_4:bigint, $hashvalue_10:bigint]
                         nationkey_4 := "expr_3"
                     - RemoteSource[3] => [expr_3:bigint, $hashvalue_10:bigint]

 Fragment 2 [SOURCE]
     Output layout: [nationkey, $hashvalue_8]
     Output partitioning: HASH [nationkey][$hashvalue_8]
     Grouped Execution: false
     - Project[] => [nationkey:bigint, $hashvalue_8:bigint]
             $hashvalue_8 := "combine_hash"(bigint '0', COALESCE("$operator$hash_code"("nationkey"), 0))
         - Aggregate(PARTIAL)[nationkey] => [nationkey:bigint]
             - TableScan[tpch:tpch:nation:sf1.0, grouped = false] => [nationkey:bigint]
                     Cost: {rows: 25 (225B), cpu: 225.00, memory: 0.00, network: 0.00}
                     nationkey := tpch:nationkey

 Fragment 3 [SINGLE]
     Output layout: [expr_3, $hashvalue_11]
     Output partitioning: HASH [expr_3][$hashvalue_11]
     Grouped Execution: false
     - Project[] => [expr_3:bigint, $hashvalue_11:bigint]
             $hashvalue_11 := "combine_hash"(bigint '0', COALESCE("$operator$hash_code"("expr_3"), 0))
         - Aggregate(PARTIAL)[expr_3] => [expr_3:bigint]
             - Project[] => [expr_3:bigint]
                     Cost: {rows: 1 (9B), cpu: 9.00, memory: 0.00, network: 0.00}
                     expr_3 := BIGINT '1'
                 - LocalExchange[ROUND_ROBIN] () =>
                         Cost: {rows: 1 (0B), cpu: 0.00, memory: 0.00, network: 0.00}
                     - Values => []
                             Cost: {rows: 1 (0B), cpu: 0.00, memory: 0.00, network: 0.00}
                             ()

Extracted-From: prestodb/presto#11957
The plannedChildren variable wasn't doing anything useful anymore so it
was just a layer of indirection.

Extracted-From: prestodb/presto#11957
@cla-bot
Copy link

cla-bot bot commented Feb 12, 2019

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to cla@prestosql.io. If you are contributing on behalf of someone else (e.g., your employer), the individual CLA may not be sufficient and your employer may need the Corporate CLA signed.

@sopel39 sopel39 merged commit b4e065c into trinodb:master Feb 12, 2019
@sopel39 sopel39 deleted the ks/union_exchange branch February 12, 2019 14:20
@sopel39 sopel39 mentioned this pull request Feb 13, 2019
6 tasks
@electrum electrum added this to the 303 milestone Feb 14, 2019
rice668 pushed a commit to rice668/trino that referenced this pull request Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants