github-6464.slt 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 database-issues#6464.
  10. # Note that this test employs the old syntax with the EXPECTED GROUP SIZE because the behavior
  11. # tested is exactly the backwards-compatible one of assigning the hinted value to all operators
  12. # in the same query block.
  13. statement ok
  14. CREATE TABLE teachers (id INT, name TEXT);
  15. statement ok
  16. CREATE TABLE sections (id INT, teacher_id INT, course_id INT, schedule TEXT);
  17. statement ok
  18. CREATE MATERIALIZED VIEW distinct_on_group_by_limit AS
  19. SELECT DISTINCT ON(teacher_id) id, teacher_id, MAX(course_id)
  20. FROM sections
  21. GROUP BY id, teacher_id
  22. OPTIONS (EXPECTED GROUP SIZE = 1000)
  23. ORDER BY teacher_id, id
  24. LIMIT 2;
  25. query T multiline
  26. EXPLAIN RAW PLAN FOR
  27. SELECT DISTINCT ON(teacher_id) id, teacher_id, MAX(course_id)
  28. FROM sections
  29. GROUP BY id, teacher_id
  30. OPTIONS (EXPECTED GROUP SIZE = 1000)
  31. ORDER BY teacher_id, id
  32. LIMIT 2;
  33. ----
  34. Finish order_by=[#1 asc nulls_last, #0 asc nulls_last] limit=2 output=[#0..=#2]
  35. TopK group_by=[#1] order_by=[#0 asc nulls_last] limit=1 exp_group_size=1000
  36. Reduce group_by=[#4, #5] aggregates=[max(#2{course_id})] exp_group_size=1000
  37. Map (#0{id}, #1{teacher_id})
  38. Get materialize.public.sections
  39. Target cluster: quickstart
  40. EOF
  41. query T multiline
  42. EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR MATERIALIZED VIEW distinct_on_group_by_limit;
  43. ----
  44. materialize.public.distinct_on_group_by_limit:
  45. TopK order_by=[#1{teacher_id} asc nulls_last, #0{id} asc nulls_last] limit=2 exp_group_size=1000
  46. TopK group_by=[#1{teacher_id}] order_by=[#0{id} asc nulls_last] limit=1 exp_group_size=1000
  47. Reduce group_by=[#0{id}, #1{teacher_id}] aggregates=[max(#2{course_id})] exp_group_size=1000
  48. Project (#0{id}..=#2{course_id})
  49. ReadStorage materialize.public.sections
  50. Source materialize.public.sections
  51. Target cluster: quickstart
  52. EOF