optimizer_notices.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. from textwrap import dedent
  10. from materialize.checks.actions import Testdrive
  11. from materialize.checks.checks import Check
  12. SCHEMA = "optimizer_notices"
  13. class OptimizerNotices(Check):
  14. def initialize(self) -> Testdrive:
  15. return Testdrive(
  16. dedent(
  17. f"""
  18. $postgres-execute connection=postgres://mz_system:materialize@${{testdrive.materialize-internal-sql-addr}}
  19. ALTER SYSTEM SET enable_mz_notices TO true
  20. > DROP SCHEMA IF EXISTS {SCHEMA} CASCADE;
  21. > CREATE SCHEMA {SCHEMA};
  22. > CREATE TABLE {SCHEMA}.t1(x INTEGER, y INTEGER);
  23. > CREATE INDEX t1_idx ON {SCHEMA}.t1(x, y);
  24. """
  25. )
  26. )
  27. def manipulate(self) -> list[Testdrive]:
  28. return [
  29. Testdrive(dedent(s))
  30. for s in [
  31. f"""
  32. # emits one "index too wide" notice
  33. > CREATE MATERIALIZED VIEW {SCHEMA}.mv1 AS SELECT x, y FROM {SCHEMA}.t1 WHERE x = 5;
  34. """,
  35. f"""
  36. # emits one "index too wide" notice and one "index key empty" notice
  37. > CREATE VIEW {SCHEMA}.v1 AS SELECT x, y FROM {SCHEMA}.t1 WHERE x = 7;
  38. > CREATE INDEX v1_idx ON {SCHEMA}.v1();
  39. """,
  40. ]
  41. ]
  42. def validate(self) -> Testdrive:
  43. return Testdrive(
  44. dedent(
  45. f"""
  46. > SELECT o.type, o.name, replace(n.notice_type, ' ', '␠')
  47. FROM mz_internal.mz_notices n
  48. JOIN mz_catalog.mz_objects o ON (o.id = n.object_id)
  49. JOIN mz_catalog.mz_schemas s ON (s.id = o.schema_id)
  50. WHERE s.name = '{SCHEMA}';
  51. index v1_idx Empty␠index␠key
  52. index v1_idx Index␠too␠wide␠for␠literal␠constraints
  53. materialized-view mv1 Index␠too␠wide␠for␠literal␠constraints
  54. """
  55. )
  56. )