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

[DNM]: Cluster-specific Optimize pipelines MVP #25165

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
explain,slt: add EXPLAIN ... VIEW test
aalexandrov committed Feb 28, 2024
commit 71fa86d24d343e905b68757528d110cfedb909a8
249 changes: 249 additions & 0 deletions test/sqllogictest/explain/view.slt
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
# Copyright Materialize, Inc. and contributors. All rights reserved.
#
# Use of this software is governed by the Business Source License
# included in the LICENSE file at the root of this repository.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.

simple conn=mz_system,user=mz_system
ALTER SYSTEM SET enable_new_outer_join_lowering TO false;
----
COMPLETE 0

statement ok
CREATE TABLE accounts(id int, balance int);

# Use `id bigint` instead of `id int` to force differences in planning based on
# the `enable_new_outer_join_lowering` feature flag value.
statement ok
CREATE TABLE account_details(id bigint, address string);

statement ok
CREATE OR REPLACE VIEW v AS
SELECT
*
FROM
accounts a
LEFT JOIN account_details ad USING(id)
WHERE
balance = 100;

mode cockroach

# Must explain the "Raw Plan".
query T multiline
EXPLAIN RAW PLAN FOR VIEW v;
----
Project (#0, #1, #3)
Filter (#1 = 100)
LeftOuterJoin (true AND (integer_to_bigint(#0) = #2))
Get materialize.public.accounts
Get materialize.public.account_details

EOF

# Must explain the "Locally Optimized Plan".
query T multiline
EXPLAIN VIEW v;
----
Return
Project (#0, #1, #3)
Union
Get l0
Project (#0, #3..=#5)
Map (100, null, null)
Join on=(#0 = #1)
Union
Negate
Distinct project=[#0]
Get l0
Distinct project=[#0]
Get l1
Get l1
With
cte l1 =
Filter (#1 = 100)
Get materialize.public.accounts
cte l0 =
Join on=(#2 = integer_to_bigint(#0))
Filter (#0) IS NOT NULL AND (#1 = 100)
Get materialize.public.accounts
Filter (#0) IS NOT NULL
Get materialize.public.account_details

EOF

# Must explain the "Locally Optimized Plan" (same as above).
query T multiline
EXPLAIN LOCALLY OPTIMIZED PLAN FOR VIEW v;
----
Return
Project (#0, #1, #3)
Union
Get l0
Project (#0, #3..=#5)
Map (100, null, null)
Join on=(#0 = #1)
Union
Negate
Distinct project=[#0]
Get l0
Distinct project=[#0]
Get l1
Get l1
With
cte l1 =
Filter (#1 = 100)
Get materialize.public.accounts
cte l0 =
Join on=(#2 = integer_to_bigint(#0))
Filter (#0) IS NOT NULL AND (#1 = 100)
Get materialize.public.accounts
Filter (#0) IS NOT NULL
Get materialize.public.account_details

EOF

# Must explain the "Locally Optimized Plan" (same as above).
query T multiline
EXPLAIN PLAN FOR REPLAN VIEW v;
----
Return
Project (#0, #1, #3)
Union
Get l0
Project (#0, #3..=#5)
Map (100, null, null)
Join on=(#0 = #1)
Union
Negate
Distinct project=[#0]
Get l0
Distinct project=[#0]
Get l1
Get l1
With
cte l1 =
Filter (#1 = 100)
Get materialize.public.accounts
cte l0 =
Join on=(#2 = integer_to_bigint(#0))
Filter (#0) IS NOT NULL AND (#1 = 100)
Get materialize.public.accounts
Filter (#0) IS NOT NULL
Get materialize.public.account_details

EOF

# Must explain the "Locally Optimized Plan" after changing the feature flag
# (same as below).
query T multiline
EXPLAIN PLAN WITH(ENABLE NEW OUTER JOIN LOWERING = TRUE) FOR REPLAN VIEW v;
----
Return
Project (#0, #1, #3)
Union
Map (null, null)
Union
Project (#0, #1)
Negate
Join on=(#2 = integer_to_bigint(#0))
Get l1
Distinct project=[integer_to_bigint(#0)]
Get l0
Get l1
Filter (#1 = 100)
Get l0
With
cte l1 =
Filter (#1 = 100)
Get materialize.public.accounts
cte l0 =
Join on=(#2 = integer_to_bigint(#0))
Filter (#0) IS NOT NULL
Get materialize.public.accounts
Filter (#0) IS NOT NULL
Get materialize.public.account_details

EOF

# Change the feature flag value
simple conn=mz_system,user=mz_system
ALTER SYSTEM SET enable_new_outer_join_lowering TO true;
----
COMPLETE 0

# Must be planning with the feature flag turned on.
statement ok
CREATE OR REPLACE VIEW v AS
SELECT
*
FROM
accounts a
LEFT JOIN account_details ad USING(id)
WHERE
balance = 100;

# Ensure that the index is now used by the view
query T multiline
EXPLAIN VIEW v;
----
Return
Project (#0, #1, #3)
Union
Map (null, null)
Union
Project (#0, #1)
Negate
Join on=(#2 = integer_to_bigint(#0))
Get l1
Distinct project=[integer_to_bigint(#0)]
Get l0
Get l1
Filter (#1 = 100)
Get l0
With
cte l1 =
Filter (#1 = 100)
Get materialize.public.accounts
cte l0 =
Join on=(#2 = integer_to_bigint(#0))
Filter (#0) IS NOT NULL
Get materialize.public.accounts
Filter (#0) IS NOT NULL
Get materialize.public.account_details

EOF

# Must be re-planning with the feature flag turned off.
query T multiline
EXPLAIN PLAN WITH(ENABLE NEW OUTER JOIN LOWERING = FALSE) FOR REPLAN VIEW v;
----
Return
Project (#0, #1, #3)
Union
Get l0
Project (#0, #3..=#5)
Map (100, null, null)
Join on=(#0 = #1)
Union
Negate
Distinct project=[#0]
Get l0
Distinct project=[#0]
Get l1
Get l1
With
cte l1 =
Filter (#1 = 100)
Get materialize.public.accounts
cte l0 =
Join on=(#2 = integer_to_bigint(#0))
Filter (#0) IS NOT NULL AND (#1 = 100)
Get materialize.public.accounts
Filter (#0) IS NOT NULL
Get materialize.public.account_details

EOF