123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- # 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 "Locally Optimized Plan".
- query T multiline
- EXPLAIN LOCALLY OPTIMIZED PLAN FOR
- VIEW v;
- ----
- With
- cte l0 =
- Join on=(#2{id} = integer_to_bigint(#0{id}))
- Filter (#1{balance} = 100) AND (#0{id}) IS NOT NULL
- Get materialize.public.accounts
- Filter (#0{id}) IS NOT NULL
- Get materialize.public.account_details
- cte l1 =
- Filter (#1 = 100)
- Get materialize.public.accounts
- 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
- EOF
- # Must explain the "Locally Optimized Plan" (same as above).
- query T multiline
- EXPLAIN LOCALLY OPTIMIZED PLAN FOR
- REPLAN VIEW v;
- ----
- With
- cte l0 =
- Join on=(#2{id} = integer_to_bigint(#0{id}))
- Filter (#1{balance} = 100) AND (#0{id}) IS NOT NULL
- Get materialize.public.accounts
- Filter (#0{id}) IS NOT NULL
- Get materialize.public.account_details
- cte l1 =
- Filter (#1 = 100)
- Get materialize.public.accounts
- 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
- EOF
- # Must explain the "Locally Optimized Plan" after changing the feature flag
- # (same as below).
- query T multiline
- EXPLAIN LOCALLY OPTIMIZED PLAN WITH(ENABLE NEW OUTER JOIN LOWERING = TRUE) FOR
- REPLAN VIEW v;
- ----
- With
- cte l0 =
- Join on=(#2{id} = integer_to_bigint(#0{id}))
- Filter (#0{id}) IS NOT NULL
- Get materialize.public.accounts
- Filter (#0{id}) IS NOT NULL
- Get materialize.public.account_details
- Return
- Project (#0, #1, #3)
- Union
- Map (null, null)
- Union
- Project (#0, #1)
- Negate
- Join on=(#2 = integer_to_bigint(#0{id}))
- Filter (#1{balance} = 100) AND (#0{id}) IS NOT NULL
- Get materialize.public.accounts
- Distinct project=[#2]
- Get l0
- Filter (#1{balance} = 100)
- Get materialize.public.accounts
- Filter (#1{balance} = 100)
- Get l0
- 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 flag was used during planning.
- query T multiline
- EXPLAIN LOCALLY OPTIMIZED PLAN FOR
- VIEW v;
- ----
- With
- cte l0 =
- Join on=(#2{id} = integer_to_bigint(#0{id}))
- Filter (#0{id}) IS NOT NULL
- Get materialize.public.accounts
- Filter (#0{id}) IS NOT NULL
- Get materialize.public.account_details
- Return
- Project (#0, #1, #3)
- Union
- Map (null, null)
- Union
- Project (#0, #1)
- Negate
- Join on=(#2 = integer_to_bigint(#0{id}))
- Filter (#1{balance} = 100) AND (#0{id}) IS NOT NULL
- Get materialize.public.accounts
- Distinct project=[#2]
- Get l0
- Filter (#1{balance} = 100)
- Get materialize.public.accounts
- Filter (#1{balance} = 100)
- Get l0
- EOF
- # Must be re-planning with the feature flag turned off.
- query T multiline
- EXPLAIN LOCALLY OPTIMIZED PLAN WITH(ENABLE NEW OUTER JOIN LOWERING = FALSE) FOR
- REPLAN VIEW v;
- ----
- With
- cte l0 =
- Join on=(#2{id} = integer_to_bigint(#0{id}))
- Filter (#1{balance} = 100) AND (#0{id}) IS NOT NULL
- Get materialize.public.accounts
- Filter (#0{id}) IS NOT NULL
- Get materialize.public.account_details
- cte l1 =
- Filter (#1 = 100)
- Get materialize.public.accounts
- 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
- EOF
- ## Constant views
- ## (Regression tests for https://github.com/MaterializeInc/database-issues/issues/8985 )
- statement ok
- CREATE VIEW v2 AS SELECT 1;
- query T multiline
- EXPLAIN LOCALLY OPTIMIZED PLAN FOR
- REPLAN VIEW v2
- ----
- Constant
- - (1)
- EOF
- query T multiline
- EXPLAIN LOCALLY OPTIMIZED PLAN FOR
- CREATE VIEW v3 AS SELECT 5;
- ----
- Constant
- - (5)
- EOF
- # LOCALLY OPTIMIZED PLAN FOR constant MV
- query T multiline
- EXPLAIN LOCALLY OPTIMIZED PLAN FOR
- CREATE MATERIALIZED VIEW v3 AS SELECT 5;
- ----
- Constant
- - (5)
- Target cluster: quickstart
- EOF
- # LOCALLY OPTIMIZED PLAN FOR constant peek
- query T multiline
- EXPLAIN LOCALLY OPTIMIZED PLAN FOR
- SELECT 5;
- ----
- Constant
- - (5)
- Target cluster: mz_catalog_server
- EOF
|