From 9d40457759da6678158cef74c8f7e03058a99c78 Mon Sep 17 00:00:00 2001 From: Fantix King Date: Mon, 26 Feb 2024 19:19:09 -0500 Subject: [PATCH] Add Config.auto_rebuild_query_cache (#6924) It's turned off by default in ClusterTestCases --- edb/buildmeta.py | 2 +- edb/lib/cfg.edgeql | 6 ++++++ edb/server/protocol/execute.pyx | 38 ++++++++++++++++++++++----------- edb/testbase/server.py | 18 +++++++++++++++- 4 files changed, 50 insertions(+), 14 deletions(-) diff --git a/edb/buildmeta.py b/edb/buildmeta.py index a0524a4cdb4..dcb7cca6b2f 100644 --- a/edb/buildmeta.py +++ b/edb/buildmeta.py @@ -55,7 +55,7 @@ # Increment this whenever the database layout or stdlib changes. -EDGEDB_CATALOG_VERSION = 2024_02_23_00_00 +EDGEDB_CATALOG_VERSION = 2024_02_26_00_00 EDGEDB_MAJOR_VERSION = 5 diff --git a/edb/lib/cfg.edgeql b/edb/lib/cfg.edgeql index 98183e160e3..b4ccce864e3 100644 --- a/edb/lib/cfg.edgeql +++ b/edb/lib/cfg.edgeql @@ -178,6 +178,12 @@ ALTER TYPE cfg::AbstractConfig { Access-Control-Allow-Origin HTTP header'; }; + CREATE PROPERTY auto_rebuild_query_cache -> std::bool { + SET default := true; + CREATE ANNOTATION std::description := + 'Recompile all cached queries on DDL if enabled.'; + }; + # Exposed backend settings follow. # When exposing a new setting, remember to modify # the _read_sys_config function to select the value diff --git a/edb/server/protocol/execute.pyx b/edb/server/protocol/execute.pyx index 0339638f3e8..860f768e92b 100644 --- a/edb/server/protocol/execute.pyx +++ b/edb/server/protocol/execute.pyx @@ -320,6 +320,12 @@ async def execute( not dbv.in_tx() and not query_unit.tx_rollback and query_unit.user_schema + and server.config_lookup( + "auto_rebuild_query_cache", + dbv.get_session_config(), + dbv.get_database_config(), + dbv.get_system_config(), + ) ): # TODO(fantix): recompile first and update cache in tx if debug.flags.func_cache: @@ -515,19 +521,27 @@ async def execute_script( conn.last_state = state if unit_group.state_serializer is not None: dbv.set_state_serializer(unit_group.state_serializer) - if not in_tx: - if any(query_unit.user_schema for query_unit in unit_group): - # TODO(fantix): recompile first and update cache in tx - if debug.flags.func_cache: - recompile_requests = await dbv.clear_cache_keys(conn) - else: - recompile_requests = [ - req - for req, (grp, _) in dbv._db._eql_to_compiled.items() - if len(grp) == 1 - ] + if ( + not in_tx + and any(query_unit.user_schema for query_unit in unit_group) + and dbv.server.config_lookup( + "auto_rebuild_query_cache", + dbv.get_session_config(), + dbv.get_database_config(), + dbv.get_system_config(), + ) + ): + # TODO(fantix): recompile first and update cache in tx + if debug.flags.func_cache: + recompile_requests = await dbv.clear_cache_keys(conn) + else: + recompile_requests = [ + req + for req, (grp, _) in dbv._db._eql_to_compiled.items() + if len(grp) == 1 + ] - await dbv.recompile_all(conn, recompile_requests) + await dbv.recompile_all(conn, recompile_requests) finally: if sent and not sync: diff --git a/edb/testbase/server.py b/edb/testbase/server.py index ab644765e55..7e021bf56fe 100644 --- a/edb/testbase/server.py +++ b/edb/testbase/server.py @@ -678,6 +678,9 @@ class ClusterTestCase(BaseHTTPTestCase): # library (e.g. declaring casts). INTERNAL_TESTMODE = True + # Turns off query cache recompilation on DDL + ENABLE_RECOMPILATION = False + # Setup and teardown commands that run per test PER_TEST_SETUP: Sequence[str] = () PER_TEST_TEARDOWN: Sequence[str] = () @@ -851,6 +854,13 @@ def setUp(self): self.con.execute( 'CONFIGURE SESSION SET __internal_testmode := true;')) + if not self.ENABLE_RECOMPILATION: + self.loop.run_until_complete( + self.con.execute( + 'CONFIGURE SESSION SET auto_rebuild_query_cache := false;' + ) + ) + if self.TRANSACTION_ISOLATION: self.xact = self.con.transaction() self.loop.run_until_complete(self.xact.start()) @@ -1167,9 +1177,13 @@ def get_api_prefix(cls): def get_setup_script(cls): script = '' - # allow the setup script to also run in test mode + # allow the setup script to also run in test mode and no recompilation if cls.INTERNAL_TESTMODE: script += '\nCONFIGURE SESSION SET __internal_testmode := true;' + if not cls.ENABLE_RECOMPILATION: + script += ( + '\nCONFIGURE SESSION SET auto_rebuild_query_cache := false;' + ) if getattr(cls, 'BACKEND_SUPERUSER', False): is_superuser = getattr(cls, 'is_superuser', True) @@ -1228,6 +1242,8 @@ def get_setup_script(cls): # allow the setup script to also run in test mode if cls.INTERNAL_TESTMODE: script += '\nCONFIGURE SESSION SET __internal_testmode := false;' + if not cls.ENABLE_RECOMPILATION: + script += '\nCONFIGURE SESSION RESET auto_rebuild_query_cache;' return script.strip(' \n')