1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- # 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.
- mode cockroach
- simple conn=mz_system,user=mz_system
- ALTER SYSTEM SET enable_eager_delta_joins TO true;
- ----
- COMPLETE 0
- # Tests for nested WITH MUTUALLY RECURSIVE
- statement ok
- CREATE TABLE edges (src int, dst int);
- statement ok
- INSERT INTO edges SELECT x, x + 1 FROM generate_series(0, 9) as x;
- statement ok
- INSERT INTO edges VALUES (4, 2), (8, 6);
- statement ok
- CREATE VIEW strongly_connected_components AS
- WITH MUTUALLY RECURSIVE
- intra_edges (src int, dst int) as (
- SELECT * FROM edges
- EXCEPT ALL
- SELECT * FROM edges_delayed
- UNION ALL
- SELECT src, dst
- FROM
- edges,
- forward_labels f_src,
- forward_labels f_dst,
- reverse_labels r_src,
- reverse_labels r_dst
- WHERE src = f_src.node
- AND src = r_src.node
- AND dst = f_dst.node
- AND dst = r_dst.node
- AND f_src.label = f_dst.label
- AND r_src.label = r_dst.label
- ),
- forward_labels (node int, label int) AS (
- WITH MUTUALLY RECURSIVE
- label (node int, comp int) AS (
- SELECT dst, MIN(comp)
- FROM (
- SELECT dst, dst AS comp FROM edges
- UNION ALL
- SELECT intra_edges.dst, label.comp
- FROM intra_edges, label
- WHERE intra_edges.src = label.node
- )
- GROUP BY dst
- )
- SELECT * FROM label
- ),
- reverse_labels (node int, label int) AS (
- WITH MUTUALLY RECURSIVE
- label (node int, comp int) AS (
- SELECT src, MIN(comp)
- FROM (
- SELECT src, src AS comp FROM edges
- UNION ALL
- SELECT intra_edges.src, label.comp
- FROM intra_edges, label
- WHERE intra_edges.dst = label.node
- )
- GROUP BY src
- )
- SELECT * FROM label
- ),
- edges_delayed (src int, dst int) AS (SELECT * FROM edges)
- SELECT * FROM forward_labels UNION SELECT * FROM reverse_labels;
- statement ok
- CREATE DEFAULT INDEX ON strongly_connected_components;
- query II
- SELECT size, COUNT(*) FROM (
- SELECT label, COUNT(*) as size
- FROM strongly_connected_components
- GROUP BY label
- )
- GROUP BY size;
- ----
- 1 5
- 3 2
|