Module materialize.checks.all_checks.optimizer_notices
Expand source code Browse git
# Copyright Materialize, Inc. and contributors. All rights reserved.
#
# Use of this software is governed by the Business Source License
# included in the LICENSE file at the root of this repository.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.
from textwrap import dedent
from materialize.checks.actions import Testdrive
from materialize.checks.checks import Check
from materialize.checks.executors import Executor
from materialize.mz_version import MzVersion
SCHEMA = "optimizer_notices"
class OptimizerNotices(Check):
def _can_run(self, e: Executor) -> bool:
return self.base_version >= MzVersion.parse_mz("v0.81.0-dev")
def initialize(self) -> Testdrive:
return Testdrive(
dedent(
f"""
$postgres-execute connection=postgres://mz_system:materialize@${{testdrive.materialize-internal-sql-addr}}
ALTER SYSTEM SET enable_mz_notices TO true
> DROP SCHEMA IF EXISTS {SCHEMA} CASCADE;
> CREATE SCHEMA {SCHEMA};
> CREATE TABLE {SCHEMA}.t1(x INTEGER, y INTEGER);
> CREATE INDEX t1_idx ON {SCHEMA}.t1(x, y);
"""
)
)
def manipulate(self) -> list[Testdrive]:
return [
Testdrive(dedent(s))
for s in [
f"""
# emits one "index too wide" notice
> CREATE MATERIALIZED VIEW {SCHEMA}.mv1 AS SELECT x, y FROM {SCHEMA}.t1 WHERE x = 5;
""",
f"""
# emits one "index too wide" notice and one "index key empty" notice
> CREATE VIEW {SCHEMA}.v1 AS SELECT x, y FROM {SCHEMA}.t1 WHERE x = 7;
> CREATE INDEX v1_idx ON {SCHEMA}.v1();
""",
]
]
def validate(self) -> Testdrive:
return Testdrive(
dedent(
f"""
$postgres-execute connection=postgres://mz_system:materialize@${{testdrive.materialize-internal-sql-addr}}
ALTER SYSTEM SET enable_rbac_checks TO false
> SELECT o.type, o.name, replace(n.notice_type, ' ', '␠')
FROM mz_internal.mz_notices n
JOIN mz_catalog.mz_objects o ON (o.id = n.object_id)
JOIN mz_catalog.mz_schemas s ON (s.id = o.schema_id)
WHERE s.name = '{SCHEMA}';
index v1_idx Empty␠index␠key
index v1_idx Index␠too␠wide␠for␠literal␠constraints
materialized-view mv1 Index␠too␠wide␠for␠literal␠constraints
$postgres-execute connection=postgres://mz_system:materialize@${{testdrive.materialize-internal-sql-addr}}
ALTER SYSTEM SET enable_rbac_checks TO true
"""
)
)
Classes
class OptimizerNotices (base_version: MzVersion, rng: random.Random | None)
-
Expand source code Browse git
class OptimizerNotices(Check): def _can_run(self, e: Executor) -> bool: return self.base_version >= MzVersion.parse_mz("v0.81.0-dev") def initialize(self) -> Testdrive: return Testdrive( dedent( f""" $postgres-execute connection=postgres://mz_system:materialize@${{testdrive.materialize-internal-sql-addr}} ALTER SYSTEM SET enable_mz_notices TO true > DROP SCHEMA IF EXISTS {SCHEMA} CASCADE; > CREATE SCHEMA {SCHEMA}; > CREATE TABLE {SCHEMA}.t1(x INTEGER, y INTEGER); > CREATE INDEX t1_idx ON {SCHEMA}.t1(x, y); """ ) ) def manipulate(self) -> list[Testdrive]: return [ Testdrive(dedent(s)) for s in [ f""" # emits one "index too wide" notice > CREATE MATERIALIZED VIEW {SCHEMA}.mv1 AS SELECT x, y FROM {SCHEMA}.t1 WHERE x = 5; """, f""" # emits one "index too wide" notice and one "index key empty" notice > CREATE VIEW {SCHEMA}.v1 AS SELECT x, y FROM {SCHEMA}.t1 WHERE x = 7; > CREATE INDEX v1_idx ON {SCHEMA}.v1(); """, ] ] def validate(self) -> Testdrive: return Testdrive( dedent( f""" $postgres-execute connection=postgres://mz_system:materialize@${{testdrive.materialize-internal-sql-addr}} ALTER SYSTEM SET enable_rbac_checks TO false > SELECT o.type, o.name, replace(n.notice_type, ' ', '␠') FROM mz_internal.mz_notices n JOIN mz_catalog.mz_objects o ON (o.id = n.object_id) JOIN mz_catalog.mz_schemas s ON (s.id = o.schema_id) WHERE s.name = '{SCHEMA}'; index v1_idx Empty␠index␠key index v1_idx Index␠too␠wide␠for␠literal␠constraints materialized-view mv1 Index␠too␠wide␠for␠literal␠constraints $postgres-execute connection=postgres://mz_system:materialize@${{testdrive.materialize-internal-sql-addr}} ALTER SYSTEM SET enable_rbac_checks TO true """ ) )
Ancestors
Methods
def initialize(self) ‑> Testdrive
-
Expand source code Browse git
def initialize(self) -> Testdrive: return Testdrive( dedent( f""" $postgres-execute connection=postgres://mz_system:materialize@${{testdrive.materialize-internal-sql-addr}} ALTER SYSTEM SET enable_mz_notices TO true > DROP SCHEMA IF EXISTS {SCHEMA} CASCADE; > CREATE SCHEMA {SCHEMA}; > CREATE TABLE {SCHEMA}.t1(x INTEGER, y INTEGER); > CREATE INDEX t1_idx ON {SCHEMA}.t1(x, y); """ ) )
def manipulate(self) ‑> list[Testdrive]
-
Expand source code Browse git
def manipulate(self) -> list[Testdrive]: return [ Testdrive(dedent(s)) for s in [ f""" # emits one "index too wide" notice > CREATE MATERIALIZED VIEW {SCHEMA}.mv1 AS SELECT x, y FROM {SCHEMA}.t1 WHERE x = 5; """, f""" # emits one "index too wide" notice and one "index key empty" notice > CREATE VIEW {SCHEMA}.v1 AS SELECT x, y FROM {SCHEMA}.t1 WHERE x = 7; > CREATE INDEX v1_idx ON {SCHEMA}.v1(); """, ] ]
def validate(self) ‑> Testdrive
-
Expand source code Browse git
def validate(self) -> Testdrive: return Testdrive( dedent( f""" $postgres-execute connection=postgres://mz_system:materialize@${{testdrive.materialize-internal-sql-addr}} ALTER SYSTEM SET enable_rbac_checks TO false > SELECT o.type, o.name, replace(n.notice_type, ' ', '␠') FROM mz_internal.mz_notices n JOIN mz_catalog.mz_objects o ON (o.id = n.object_id) JOIN mz_catalog.mz_schemas s ON (s.id = o.schema_id) WHERE s.name = '{SCHEMA}'; index v1_idx Empty␠index␠key index v1_idx Index␠too␠wide␠for␠literal␠constraints materialized-view mv1 Index␠too␠wide␠for␠literal␠constraints $postgres-execute connection=postgres://mz_system:materialize@${{testdrive.materialize-internal-sql-addr}} ALTER SYSTEM SET enable_rbac_checks TO true """ ) )