render-delta-join.td 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. # Remove references to internal table identifiers and "materialize.public" strings
  10. $ set-regex match=(\s\(u\d+\)|materialize\.public\.) replacement=
  11. > CREATE TABLE t1(f1 INT, f2 INT);
  12. > CREATE INDEX i1 ON t1(f1);
  13. > CREATE TABLE t2(f1 INT, f2 INT);
  14. > CREATE INDEX i2 ON t2(f1);
  15. > INSERT INTO t1 VALUES (1, 2);
  16. > INSERT INTO t2 SELECT s, s FROM generate_series(0, 2000) AS s;
  17. > select count(*) as count from t2;
  18. count
  19. ----
  20. 2001
  21. > CREATE VIEW delta_join (t1_f1, t1_f2, t2_f1, t2_f2) AS SELECT * FROM t1, t2 WHERE t1.f1 = t2.f1;
  22. # This should cause a delta join to be executed.
  23. # But this test is currently broken: https://github.com/MaterializeInc/database-issues/issues/4772
  24. > SELECT COUNT(*) FROM delta_join;
  25. count
  26. ----
  27. 1
  28. ? EXPLAIN OPTIMIZED PLAN WITH(join implementations) AS VERBOSE TEXT FOR SELECT * FROM delta_join;
  29. Explained Query:
  30. Project (#0, #1, #0, #3)
  31. Filter (#0{f1}) IS NOT NULL
  32. Join on=(#0{f1} = #2{f1}) type=differential
  33. implementation
  34. %0:t1[#0{f1}]KA » %1:t2[#0{f1}]KA
  35. ArrangeBy keys=[[#0{f1}]]
  36. ReadIndex on=t1 i1=[differential join]
  37. ArrangeBy keys=[[#0{f1}]]
  38. ReadIndex on=t2 i2=[differential join]
  39. Used Indexes:
  40. - i1 (differential join)
  41. - i2 (differential join)
  42. Target cluster: quickstart
  43. > SELECT count(*) AS count FROM delta_join;
  44. count
  45. ----
  46. 1
  47. # The purpose of this test is to check that only the first delta path sees updates
  48. # at start-up time. According to the plan above, only t1's path will see them, so
  49. # the delta path for t2 won't see the 2000 rows in t2. 100 is used as an arbitrary
  50. # threshold since the actual number of messages sent depends on the number of
  51. # workers.
  52. # In case the environment has other replicas
  53. > SET cluster_replica = r1
  54. > SELECT
  55. sent
  56. FROM
  57. mz_introspection.mz_dataflow_channels AS channels
  58. LEFT JOIN mz_introspection.mz_message_counts AS counts
  59. ON channels.id = counts.channel_id
  60. WHERE
  61. id IN
  62. (SELECT id
  63. FROM mz_introspection.mz_dataflow_addresses
  64. WHERE address[1] =
  65. (SELECT id
  66. FROM mz_introspection.mz_dataflows
  67. WHERE name LIKE '%.delta_join%'))
  68. AND sent > 100
  69. ORDER BY sent;
  70. sent
  71. ----