distinct_on.slt 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Copyright 2015 - 2019 The Cockroach Authors. All rights reserved.
  2. # Copyright Materialize, Inc. and contributors. All rights reserved.
  3. #
  4. # Use of this software is governed by the Business Source License
  5. # included in the LICENSE file at the root of this repository.
  6. #
  7. # As of the Change Date specified in that file, in accordance with
  8. # the Business Source License, use of this software will be governed
  9. # by the Apache License, Version 2.0.
  10. #
  11. # This file is derived from the logic test suite in CockroachDB. The
  12. # original file was retrieved on June 10, 2019 from:
  13. #
  14. # https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/distinct_on
  15. #
  16. # The original source code is subject to the terms of the Apache
  17. # 2.0 license, a copy of which can be found in the LICENSE file at the
  18. # root of this repository.
  19. # The tests in this file lock in plans for DISTINCT ON. Correctness tests are in
  20. # cockroach/distinct_on.slt.
  21. statement ok
  22. CREATE TABLE abc (
  23. a text,
  24. b text,
  25. c text
  26. )
  27. query T multiline
  28. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR SELECT DISTINCT ON (c) a FROM abc
  29. ----
  30. Explained Query:
  31. Project (#0{a}) // { arity: 1 }
  32. TopK group_by=[#1{c}] limit=1 // { arity: 2 }
  33. Project (#0{a}, #2{c}) // { arity: 2 }
  34. ReadStorage materialize.public.abc // { arity: 3 }
  35. Source materialize.public.abc
  36. Target cluster: quickstart
  37. EOF
  38. query T multiline
  39. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR SELECT DISTINCT ON (c) a FROM abc ORDER BY c, b
  40. ----
  41. Explained Query:
  42. Finish order_by=[#2{c} asc nulls_last, #1{b} asc nulls_last] output=[#0]
  43. TopK group_by=[#2{c}] order_by=[#1{b} asc nulls_last] limit=1 // { arity: 3 }
  44. ReadStorage materialize.public.abc // { arity: 3 }
  45. Source materialize.public.abc
  46. Target cluster: quickstart
  47. EOF