From 0efb897706c288b5164445328186619fb65b6255 Mon Sep 17 00:00:00 2001 From: Gokhan Gulbiz Date: Thu, 23 Mar 2023 11:51:09 +0300 Subject: [PATCH] Test local cached queries & prepared statements --- .../regress/expected/citus_stats_tenants.out | 211 ++++++++++++++++++ src/test/regress/sql/citus_stats_tenants.sql | 56 +++++ 2 files changed, 267 insertions(+) diff --git a/src/test/regress/expected/citus_stats_tenants.out b/src/test/regress/expected/citus_stats_tenants.out index becbfdd27..8623676fb 100644 --- a/src/test/regress/expected/citus_stats_tenants.out +++ b/src/test/regress/expected/citus_stats_tenants.out @@ -383,6 +383,7 @@ SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, q (6 rows) \c - - - :worker_2_port +SET search_path TO citus_stats_tenants; SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants ORDER BY tenant_attribute; tenant_attribute | read_count_in_this_period | read_count_in_last_period | query_count_in_this_period | query_count_in_last_period --------------------------------------------------------------------- @@ -392,6 +393,216 @@ SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, q bcde* | 1 | 0 | 1 | 0 (4 rows) +SELECT result FROM run_command_on_all_nodes('SELECT clean_citus_stats_tenants()'); + result +--------------------------------------------------------------------- + + +(2 rows) + +-- test local queries +SELECT count(*)>=0 FROM dist_tbl_text WHERE a = '/b*c/de'; + ?column? +--------------------------------------------------------------------- + t +(1 row) + +SELECT count(*)>=0 FROM dist_tbl_text WHERE a = '/bcde'; + ?column? +--------------------------------------------------------------------- + t +(1 row) + +SELECT count(*)>=0 FROM dist_tbl_text WHERE a = U&'\0061\0308bc'; + ?column? +--------------------------------------------------------------------- + t +(1 row) + +SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'bcde*'; + ?column? +--------------------------------------------------------------------- + t +(1 row) + +SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants ORDER BY tenant_attribute; + tenant_attribute | read_count_in_this_period | read_count_in_last_period | query_count_in_this_period | query_count_in_last_period +--------------------------------------------------------------------- + /b*c/de | 1 | 0 | 1 | 0 + /bcde | 1 | 0 | 1 | 0 + äbc | 1 | 0 | 1 | 0 + bcde* | 1 | 0 | 1 | 0 +(4 rows) + +-- test local cached queries & prepared statements +PREPARE dist_tbl_text_select_plan (text) AS SELECT count(*)>=0 FROM dist_tbl_text WHERE a = $1; +EXECUTE dist_tbl_text_select_plan('/b*c/de'); + ?column? +--------------------------------------------------------------------- + t +(1 row) + +EXECUTE dist_tbl_text_select_plan('/bcde'); + ?column? +--------------------------------------------------------------------- + t +(1 row) + +EXECUTE dist_tbl_text_select_plan(U&'\0061\0308bc'); + ?column? +--------------------------------------------------------------------- + t +(1 row) + +EXECUTE dist_tbl_text_select_plan('bcde*'); + ?column? +--------------------------------------------------------------------- + t +(1 row) + +EXECUTE dist_tbl_text_select_plan('/b*c/de'); + ?column? +--------------------------------------------------------------------- + t +(1 row) + +EXECUTE dist_tbl_text_select_plan('/bcde'); + ?column? +--------------------------------------------------------------------- + t +(1 row) + +EXECUTE dist_tbl_text_select_plan(U&'\0061\0308bc'); + ?column? +--------------------------------------------------------------------- + t +(1 row) + +EXECUTE dist_tbl_text_select_plan('bcde*'); + ?column? +--------------------------------------------------------------------- + t +(1 row) + +EXECUTE dist_tbl_text_select_plan('/b*c/de'); + ?column? +--------------------------------------------------------------------- + t +(1 row) + +EXECUTE dist_tbl_text_select_plan('/bcde'); + ?column? +--------------------------------------------------------------------- + t +(1 row) + +EXECUTE dist_tbl_text_select_plan(U&'\0061\0308bc'); + ?column? +--------------------------------------------------------------------- + t +(1 row) + +EXECUTE dist_tbl_text_select_plan('bcde*'); + ?column? +--------------------------------------------------------------------- + t +(1 row) + +SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants ORDER BY tenant_attribute; + tenant_attribute | read_count_in_this_period | read_count_in_last_period | query_count_in_this_period | query_count_in_last_period +--------------------------------------------------------------------- + /b*c/de | 4 | 0 | 4 | 0 + /bcde | 4 | 0 | 4 | 0 + äbc | 4 | 0 | 4 | 0 + bcde* | 4 | 0 | 4 | 0 +(4 rows) + +\c - - - :master_port +SET search_path TO citus_stats_tenants; +PREPARE dist_tbl_text_select_plan (text) AS SELECT count(*)>=0 FROM dist_tbl_text WHERE a = $1; +EXECUTE dist_tbl_text_select_plan('/b*c/de'); + ?column? +--------------------------------------------------------------------- + t +(1 row) + +EXECUTE dist_tbl_text_select_plan('/bcde'); + ?column? +--------------------------------------------------------------------- + t +(1 row) + +EXECUTE dist_tbl_text_select_plan(U&'\0061\0308bc'); + ?column? +--------------------------------------------------------------------- + t +(1 row) + +EXECUTE dist_tbl_text_select_plan('bcde*'); + ?column? +--------------------------------------------------------------------- + t +(1 row) + +EXECUTE dist_tbl_text_select_plan('/b*c/de'); + ?column? +--------------------------------------------------------------------- + t +(1 row) + +EXECUTE dist_tbl_text_select_plan('/bcde'); + ?column? +--------------------------------------------------------------------- + t +(1 row) + +EXECUTE dist_tbl_text_select_plan(U&'\0061\0308bc'); + ?column? +--------------------------------------------------------------------- + t +(1 row) + +EXECUTE dist_tbl_text_select_plan('bcde*'); + ?column? +--------------------------------------------------------------------- + t +(1 row) + +EXECUTE dist_tbl_text_select_plan('/b*c/de'); + ?column? +--------------------------------------------------------------------- + t +(1 row) + +EXECUTE dist_tbl_text_select_plan('/bcde'); + ?column? +--------------------------------------------------------------------- + t +(1 row) + +EXECUTE dist_tbl_text_select_plan(U&'\0061\0308bc'); + ?column? +--------------------------------------------------------------------- + t +(1 row) + +EXECUTE dist_tbl_text_select_plan('bcde*'); + ?column? +--------------------------------------------------------------------- + t +(1 row) + +\c - - - :worker_2_port +SET search_path TO citus_stats_tenants; +SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants ORDER BY tenant_attribute; + tenant_attribute | read_count_in_this_period | read_count_in_last_period | query_count_in_this_period | query_count_in_last_period +--------------------------------------------------------------------- + /b*c/de | 7 | 0 | 7 | 0 + /bcde | 7 | 0 | 7 | 0 + äbc | 7 | 0 | 7 | 0 + bcde* | 7 | 0 | 7 | 0 +(4 rows) + \c - - - :master_port SET client_min_messages TO ERROR; DROP SCHEMA citus_stats_tenants CASCADE; diff --git a/src/test/regress/sql/citus_stats_tenants.sql b/src/test/regress/sql/citus_stats_tenants.sql index 1e52b7705..8f031bf18 100644 --- a/src/test/regress/sql/citus_stats_tenants.sql +++ b/src/test/regress/sql/citus_stats_tenants.sql @@ -128,7 +128,63 @@ SELECT count(*)>=0 FROM dist_tbl_text WHERE a = U&'\0061\0308bc'; \c - - - :worker_1_port SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants ORDER BY tenant_attribute; \c - - - :worker_2_port +SET search_path TO citus_stats_tenants; + SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants ORDER BY tenant_attribute; + +SELECT result FROM run_command_on_all_nodes('SELECT clean_citus_stats_tenants()'); + +-- test local queries + +SELECT count(*)>=0 FROM dist_tbl_text WHERE a = '/b*c/de'; +SELECT count(*)>=0 FROM dist_tbl_text WHERE a = '/bcde'; +SELECT count(*)>=0 FROM dist_tbl_text WHERE a = U&'\0061\0308bc'; +SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'bcde*'; + +SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants ORDER BY tenant_attribute; + +-- test local cached queries & prepared statements + +PREPARE dist_tbl_text_select_plan (text) AS SELECT count(*)>=0 FROM dist_tbl_text WHERE a = $1; + +EXECUTE dist_tbl_text_select_plan('/b*c/de'); +EXECUTE dist_tbl_text_select_plan('/bcde'); +EXECUTE dist_tbl_text_select_plan(U&'\0061\0308bc'); +EXECUTE dist_tbl_text_select_plan('bcde*'); +EXECUTE dist_tbl_text_select_plan('/b*c/de'); +EXECUTE dist_tbl_text_select_plan('/bcde'); +EXECUTE dist_tbl_text_select_plan(U&'\0061\0308bc'); +EXECUTE dist_tbl_text_select_plan('bcde*'); +EXECUTE dist_tbl_text_select_plan('/b*c/de'); +EXECUTE dist_tbl_text_select_plan('/bcde'); +EXECUTE dist_tbl_text_select_plan(U&'\0061\0308bc'); +EXECUTE dist_tbl_text_select_plan('bcde*'); + +SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants ORDER BY tenant_attribute; + +\c - - - :master_port +SET search_path TO citus_stats_tenants; + +PREPARE dist_tbl_text_select_plan (text) AS SELECT count(*)>=0 FROM dist_tbl_text WHERE a = $1; + +EXECUTE dist_tbl_text_select_plan('/b*c/de'); +EXECUTE dist_tbl_text_select_plan('/bcde'); +EXECUTE dist_tbl_text_select_plan(U&'\0061\0308bc'); +EXECUTE dist_tbl_text_select_plan('bcde*'); +EXECUTE dist_tbl_text_select_plan('/b*c/de'); +EXECUTE dist_tbl_text_select_plan('/bcde'); +EXECUTE dist_tbl_text_select_plan(U&'\0061\0308bc'); +EXECUTE dist_tbl_text_select_plan('bcde*'); +EXECUTE dist_tbl_text_select_plan('/b*c/de'); +EXECUTE dist_tbl_text_select_plan('/bcde'); +EXECUTE dist_tbl_text_select_plan(U&'\0061\0308bc'); +EXECUTE dist_tbl_text_select_plan('bcde*'); + +\c - - - :worker_2_port +SET search_path TO citus_stats_tenants; + +SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants ORDER BY tenant_attribute; + \c - - - :master_port SET client_min_messages TO ERROR;