pushdown.slt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. mode cockroach
  10. # Disable persist inline writes so we get real part numbers below
  11. simple conn=mz_system,user=mz_system
  12. ALTER SYSTEM SET persist_inline_writes_single_max_bytes = 0
  13. ----
  14. COMPLETE 0
  15. # EXPLAIN FILTER PUSHDOWN statements are blocked by a feature flag
  16. statement ok
  17. CREATE TABLE numbers (
  18. value int
  19. );
  20. query T multiline
  21. EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR SELECT * FROM numbers where value > 10;
  22. ----
  23. Explained Query:
  24. Filter (#0{value} > 10)
  25. ReadStorage materialize.public.numbers
  26. Source materialize.public.numbers
  27. filter=((#0{value} > 10))
  28. Target cluster: quickstart
  29. EOF
  30. simple conn=mz_system,user=mz_system
  31. ALTER SYSTEM SET enable_explain_pushdown = false
  32. ----
  33. COMPLETE 0
  34. query error db error: ERROR: EXPLAIN FILTER PUSHDOWN is not available
  35. EXPLAIN FILTER PUSHDOWN FOR SELECT * FROM numbers where value > 10;
  36. # Even when the feature flag is enabled, the feature is blocked in adapter for most queries
  37. simple conn=mz_system,user=mz_system
  38. ALTER SYSTEM SET enable_explain_pushdown = true
  39. ----
  40. COMPLETE 0
  41. query error db error: ERROR: EXPLAIN FILTER PUSHDOWN queries for this explainee type are not supported
  42. EXPLAIN FILTER PUSHDOWN FOR CREATE MATERIALIZED VIEW foo AS SELECT * FROM numbers where value > 10;
  43. # However, EXPLAIN FILTER PUSHDOWN FOR SELECT is now supported
  44. query TIIII
  45. EXPLAIN FILTER PUSHDOWN FOR SELECT * FROM numbers where value > 10;
  46. ----
  47. materialize.public.numbers 0 0 0 0
  48. statement ok
  49. INSERT INTO numbers VALUES (1), (2), (3);
  50. # The next two queries may be slightly brittle, since they depend on part sizes.
  51. # Feel free to --rewrite-results or delete them if they prove difficult to maintain.
  52. query TIIII
  53. EXPLAIN FILTER PUSHDOWN FOR SELECT * FROM numbers where value > 10;
  54. ----
  55. materialize.public.numbers 1233 0 1 0
  56. query TIIII
  57. EXPLAIN FILTER PUSHDOWN FOR SELECT * FROM numbers where value < 10;
  58. ----
  59. materialize.public.numbers 1233 1233 1 1
  60. # Verify that pushdown of jsonb_get_string is infallible. Before this was
  61. # fixed, a filter expression on a jsonb field that is not present in all parts
  62. # would cause those parts to be fetched, even when AND'ed together with an
  63. # expression that would definitely filter out the part otherwise.
  64. statement ok
  65. CREATE TABLE jsonb_fields (
  66. timestamp int,
  67. payload jsonb
  68. );
  69. statement ok
  70. INSERT INTO jsonb_fields VALUES (1, '{ "field": "value" }');
  71. statement ok
  72. INSERT INTO jsonb_fields VALUES (2, '{ "other-field": "value" }');
  73. # The `timestamp > 1000` part filters out everything, regardless of whether the
  74. # referenced field exists in the payload or not.
  75. query TIIII
  76. EXPLAIN FILTER PUSHDOWN FOR SELECT * FROM jsonb_fields where timestamp > 1000 AND payload->>'field' = 'not-value';
  77. ----
  78. materialize.public.jsonb_fields 2826 0 2 0
  79. # EXPLAIN FILTER PUSHDOWN FOR MATERIALIZED VIEW is also supported
  80. statement ok
  81. CREATE MATERIALIZED VIEW big_numbers AS SELECT * FROM numbers WHERE value > 10000;
  82. statement ok
  83. SELECT mz_unsafe.mz_sleep(3);
  84. query TIIII
  85. EXPLAIN FILTER PUSHDOWN FOR MATERIALIZED VIEW big_numbers
  86. ----
  87. materialize.public.numbers 1233 0 1 0
  88. # EXPLAIN FILTER PUSHDOWN should work even if there are no replicas.
  89. statement ok
  90. CREATE CLUSTER no_replicas (SIZE '1', REPLICATION FACTOR 0);
  91. statement ok
  92. SET CLUSTER = no_replicas;
  93. query TIIII
  94. EXPLAIN FILTER PUSHDOWN FOR SELECT * FROM jsonb_fields where timestamp > 1000 AND payload->>'field' = 'not-value';
  95. ----
  96. materialize.public.jsonb_fields 2826 0 2 0
  97. # ----------------------------------------
  98. # Cleanup
  99. # ----------------------------------------
  100. simple conn=mz_system,user=mz_system
  101. ALTER SYSTEM SET enable_explain_pushdown = false
  102. ----
  103. COMPLETE 0