github-17808.slt 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. # Regression test for issues corrected by materialize#17808.
  10. # The following query should not frustrate the system, although it did prior to
  11. # the associated PR being merged. It should produce an empty result set.
  12. query I
  13. with mutually recursive
  14. a(x int) as (select * from a)
  15. select * from a;
  16. ----
  17. statement ok
  18. CREATE TABLE foo (a int)
  19. # The following query should not inline `a` into `c`, as doing so would change
  20. # the reference to `b` from "the prior iterate" to "the current iterate", at which
  21. # point it could be canceled out, which would be incorrect.
  22. # This query may need to be improved as `with mutually recursive` analysis improves,
  23. # as it is not semantically complicated just syntactically complicated.
  24. query T multiline
  25. EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR with mutually recursive
  26. a(x int) as (select * from b),
  27. b(x int) as (select * from foo),
  28. -- meant to contain `b` minus its previous iterate.
  29. c(x int) as (select * from b except all select * from a)
  30. select * from c;
  31. ----
  32. Explained Query:
  33. With Mutually Recursive
  34. cte l0 =
  35. Get l1
  36. cte l1 =
  37. ReadStorage materialize.public.foo
  38. Return
  39. Threshold
  40. Union
  41. ReadStorage materialize.public.foo
  42. Negate
  43. Get l0
  44. Source materialize.public.foo
  45. Target cluster: quickstart
  46. EOF