mysql_wmr.sql 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. -- TPC-H Query #Q18, chosen for the workload for its GROUP BY clause
  10. -- We have modified the predicate to sum(l_quantity) > 250
  11. -- to ensure the result updates frequently
  12. -- depends_on: {{ ref('mysql_cdc') }}
  13. -- depends_on: {{ ref('mysql_people') }}
  14. -- depends_on: {{ ref('mysql_relationships') }}
  15. {{ config(materialized='materialized_view', cluster="qa_canary_environment_compute", indexes=[{'default': True}]) }}
  16. WITH MUTUALLY RECURSIVE
  17. symm (a int, b int) AS (
  18. SELECT a, b FROM {{ source('mysql_cdc', 'mysql_relationships') }}
  19. UNION
  20. SELECT b, a FROM {{ source('mysql_cdc', 'mysql_relationships') }}
  21. ),
  22. candidates (a int, b int, degree int) AS (
  23. SELECT a, b, 1 FROM symm
  24. UNION
  25. SELECT symm.a, reach.b, reach.degree + 1
  26. FROM symm, reach
  27. WHERE symm.b = reach.a
  28. ),
  29. reach(a int, b int, degree int) AS (
  30. SELECT a, b, min(degree) FROM candidates group by a, b HAVING a != b
  31. )
  32. SELECT DISTINCT a_people.name AS a_name, b_people.name AS b_name, degree
  33. FROM reach
  34. LEFT JOIN {{ source('mysql_cdc', 'mysql_people') }} AS a_people ON (a = a_people.id)
  35. LEFT JOIN {{ source('mysql_cdc', 'mysql_people') }} AS b_people ON (b = b_people.id)
  36. WHERE degree >= 2