100-data-integrity.sql 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. CREATE OR REPLACE VIEW v_data_integrity (table_name, own_item_key, referenced_item_key, problem) AS
  10. -- violated references
  11. SELECT 'build_job', build_job_id, build_id, 'build job references missing build'
  12. FROM build_job
  13. WHERE build_id NOT IN (SELECT build_id FROM build)
  14. UNION
  15. SELECT 'feature_benchmark_result', build_job_id, build_job_id, 'feature benchmark result references missing build job'
  16. FROM feature_benchmark_result
  17. WHERE build_job_id NOT IN (SELECT build_job_id FROM build_job)
  18. UNION
  19. SELECT 'scalability_framework_result', build_job_id, build_job_id, 'scalability result references missing build job'
  20. FROM scalability_framework_result
  21. WHERE build_job_id NOT IN (SELECT build_job_id FROM build_job)
  22. UNION
  23. SELECT 'parallel_benchmark_result', build_job_id, build_job_id, 'parallel benchmark result references missing build job'
  24. FROM parallel_benchmark_result
  25. WHERE build_job_id NOT IN (SELECT build_job_id FROM build_job)
  26. UNION
  27. SELECT 'product_limits_result', build_job_id, build_job_id, 'product limits result references missing build job'
  28. FROM product_limits_result
  29. WHERE build_job_id NOT IN (SELECT build_job_id FROM build_job)
  30. UNION
  31. SELECT 'build_annotation', build_job_id, build_job_id, 'build annotation references missing build job'
  32. FROM build_annotation
  33. WHERE build_job_id NOT IN (SELECT build_job_id FROM build_job)
  34. UNION
  35. SELECT 'build_annotation_error', build_job_id, build_job_id, 'build annotation error references missing build annotation'
  36. FROM build_annotation_error
  37. WHERE build_job_id NOT IN (SELECT build_job_id FROM build_annotation)
  38. UNION
  39. SELECT 'feature_benchmark_discarded_result', build_job_id, scenario_name, 'discarded benchmark result without actual result'
  40. FROM feature_benchmark_discarded_result
  41. WHERE (build_job_id, scenario_name) NOT IN (SELECT build_job_id, scenario_name FROM feature_benchmark_result)
  42. -- duplicate entries
  43. UNION
  44. SELECT 'build', build_id, NULL, 'duplicate build'
  45. FROM build
  46. GROUP BY build_id
  47. HAVING count(*) > 1
  48. UNION
  49. SELECT 'build_job', build_job_id, NULL, 'duplicate build job'
  50. FROM build_job
  51. GROUP BY build_job_id
  52. HAVING count(*) > 1
  53. UNION
  54. SELECT 'build_annotation', build_job_id, NULL, 'duplicate annotation for build job'
  55. FROM build_annotation
  56. GROUP BY build_job_id
  57. HAVING count(*) > 1
  58. -- other
  59. UNION
  60. SELECT 'build_job', build_job_id, NULL, 'build job id is not unique'
  61. FROM build_job
  62. GROUP BY build_job_id
  63. HAVING count(distinct build_id) > 1
  64. UNION
  65. SELECT 'build_job', concat(build_step_key, ', shard ', shard_index), max(build_job_id), 'multiple build jobs as latest retry'
  66. FROM build_job
  67. GROUP BY build_id, build_step_key, shard_index
  68. HAVING sum(CASE WHEN is_latest_retry THEN 1 ELSE 0 END) > 1
  69. UNION
  70. SELECT 'build', build_id, NULL, 'build without build jobs'
  71. FROM build
  72. WHERE NOT EXISTS (SELECT 1 FROM build_job WHERE build_id = build.build_id)
  73. UNION
  74. SELECT 'build_annotation', build_job_id, NULL, 'build job with multiple annotation entries'
  75. FROM build_annotation
  76. GROUP BY build_job_id
  77. HAVING count(*) > 1
  78. UNION
  79. SELECT 'config', 'config', NULL, 'more than one config entry exists'
  80. FROM config
  81. HAVING count(*) > 1
  82. UNION
  83. SELECT 'issue', issue_id, NULL, 'more than one issue entry exists'
  84. FROM issue
  85. GROUP BY issue_id
  86. HAVING count(*) > 1
  87. ;
  88. ALTER VIEW v_data_integrity OWNER TO qa;