Skip to content

Commit c5c1ca6

Browse files
committed
Feature: new PGPOOL SET CACHE DELETE command.
The new PGPOOl SET command allows to delete query cache by specifying the previous query used to create the query cache entry. example usage is: PGPOOL SET CACHE DELETE 'SELECT * FROM t1;' This command is particularly useful for queries that are not invalidated by the auto cache invalidation feature because the query does not have any reference to tables.
1 parent b58a3c6 commit c5c1ca6

File tree

11 files changed

+315
-0
lines changed

11 files changed

+315
-0
lines changed

doc.ja/src/sgml/ref/allfiles.sgml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Complete list of usable sgml source files in this directory.
3030
<!ENTITY pgpoolShow SYSTEM "pgpool_show.sgml">
3131
<!ENTITY pgpoolReset SYSTEM "pgpool_reset.sgml">
3232
<!ENTITY pgpoolSet SYSTEM "pgpool_set.sgml">
33+
<!ENTITY pgpoolSetCache SYSTEM "pgpool_set_cache.sgml">
3334
<!ENTITY showPoolStatus SYSTEM "show_pool_status.sgml">
3435
<!ENTITY showPoolNodes SYSTEM "show_pool_nodes.sgml">
3536
<!ENTITY showPoolProcesses SYSTEM "show_pool_processes.sgml">
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<!--
2+
doc/src/sgml/ref/set.sgml
3+
PostgreSQL documentation
4+
-->
5+
6+
<refentry id="SQL-PGPOOL-SET-CACHE">
7+
<indexterm zone="sql-pgpool-set-cache">
8+
<primary>PGPOOL SET</primary>
9+
</indexterm>
10+
11+
<refmeta>
12+
<refentrytitle>PGPOOL SET CACHE</refentrytitle>
13+
<manvolnum>1</manvolnum>
14+
<refmiscinfo>SQL - Language Statements</refmiscinfo>
15+
</refmeta>
16+
17+
<refnamediv>
18+
<refname>PGPOOL SET CACHE</refname>
19+
<!--
20+
<refpurpose>delete query cache</refpurpose>
21+
-->
22+
<refpurpose>クエリキャッシュを削除する</refpurpose>
23+
</refnamediv>
24+
25+
<refsynopsisdiv>
26+
<synopsis>
27+
PGPOOL SET CACHE DELETE <replaceable class="PARAMETER">'query'</replaceable>
28+
</synopsis>
29+
</refsynopsisdiv>
30+
31+
<refsect1>
32+
<!--
33+
<title>Description</title>
34+
-->
35+
<title>説明</title>
36+
37+
<para>
38+
<!--
39+
The <command>PGPOOL SET CACHE DELETE</command> command deletes the
40+
<link linkend="runtime-in-memory-query-cache">query cache</link>
41+
previously created by the query. The query string must be exactly
42+
identical to the previous query, including
43+
trailing <literal>';'</literal>. Nevertheless if the query
44+
includes <literal>'</literal> (single quore), it needs to be
45+
prefixed by <literal>'</literal> like:
46+
-->
47+
<command>PGPOOL SET CACHE DELETE</command>コマンドは、以前のクエリで作成された<link linkend="runtime-in-memory-query-cache">クエリキャッシュ</link>を削除します。
48+
クエリ文字列は、末尾の<literal>';'</literal>も含めて以前のクエリと完全に一致していなければなりません。
49+
にもかかわらず、<literal>'</literal> (単一引用符)がクエリに含まれている場合は、以下のように<literal>'</literal>を前に追加する必要があります。
50+
<programlisting>
51+
PGPOOL SET CACHE DELETE 'SELECT ''FOO'';';
52+
</programlisting>
53+
<!--
54+
This command is particularly useful for queries that are not
55+
invalidated by
56+
the <link linkend="guc-memqcache-auto-cache-invalidation">auto
57+
cache invalidation feature</link> because the query does not have
58+
any reference to tables.
59+
-->
60+
このコマンドはとりわけ、クエリ中にテーブル参照を含んでいないために<link linkend="guc-memqcache-auto-cache-invalidation">自動キャッシュ削除機能</link>で削除されないクエリに有用です。
61+
</para>
62+
<para>
63+
<!--
64+
If you do not remember the previous query, you can
65+
use <xref linkend="PCP-INVALIDATE-QUERY-CACHE"> to delete all the
66+
query cache including the cache you want to delete. However it
67+
requires the <productname>Pgpool-II</productname> admin privilege.
68+
-->
69+
以前のクエリが思い出せない時は、<xref linkend="PCP-INVALIDATE-QUERY-CACHE">を使って、削除したいクエリキャッシュも含み、すべてのクエリキャッシュを削除することができます。
70+
ただし、これは<productname>Pgpool-II</productname>の管理者権限が必要になります。
71+
</para>
72+
<para>
73+
<!--
74+
Upon successful deletion of the query cache, this command emits a
75+
notice message:
76+
-->
77+
クエリキャッシュの削除に成功すると、以下のNOTICEメッセージを表示します。
78+
<programlisting>
79+
NOTICE: query cache deleted. query: "<literal>query string</literal>"
80+
</programlisting>
81+
<!--
82+
If the cache does not exist or query cache is not enabled, it emits
83+
a notice message:
84+
-->
85+
クエリキャッシュが存在しないか、クエリキャッシュが無効の場合には、以下のNOTICEメッセージを表示します。
86+
<programlisting>
87+
NOTICE: query cache does not exist for query: "<literal>query string</literal>"
88+
</programlisting>
89+
</para>
90+
</refsect1>
91+
92+
<refsect1>
93+
<!--
94+
<title>Examples</title>
95+
-->
96+
<title>例</title>
97+
98+
<para>
99+
<!--
100+
Accidentally created an unwanted query cache. Delete it by using
101+
the command.
102+
-->
103+
間違って希望しないクエリキャッシュを作成してしまいました。
104+
以下のコマンドで削除します。
105+
<programlisting>
106+
test=# /*FORCE QUERY CACHE*/SELECT current_timestamp;
107+
current_timestamp
108+
-------------------------------
109+
2024-10-18 18:25:07.826423+09
110+
(1 row)
111+
112+
test=# PGPOOL SET CACHE DELETE '/*FORCE QUERY CACHE*/SELECT current_timestamp;';
113+
NOTICE: query cache deleted. query: "/*FORCE QUERY CACHE*/SELECT current_timestamp;"
114+
SET
115+
</programlisting>
116+
</para>
117+
118+
</refsect1>
119+
120+
<refsect1>
121+
<!--
122+
<title>See Also</title>
123+
-->
124+
<title>関連項目</title>
125+
126+
<simplelist type="inline">
127+
<member><xref linkend="PCP-INVALIDATE-QUERY-CACHE"></member>
128+
</simplelist>
129+
</refsect1>
130+
131+
</refentry>

doc.ja/src/sgml/reference.sgml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@
222222

223223
&pgpoolShow
224224
&pgpoolSet
225+
&pgpoolSetCache
225226
&pgpoolReset
226227
&showPoolStatus
227228
&showPoolNodes

doc/src/sgml/ref/allfiles.sgml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Complete list of usable sgml source files in this directory.
3030
<!ENTITY pgpoolShow SYSTEM "pgpool_show.sgml">
3131
<!ENTITY pgpoolReset SYSTEM "pgpool_reset.sgml">
3232
<!ENTITY pgpoolSet SYSTEM "pgpool_set.sgml">
33+
<!ENTITY pgpoolSetCache SYSTEM "pgpool_set_cache.sgml">
3334
<!ENTITY showPoolStatus SYSTEM "show_pool_status.sgml">
3435
<!ENTITY showPoolNodes SYSTEM "show_pool_nodes.sgml">
3536
<!ENTITY showPoolProcesses SYSTEM "show_pool_processes.sgml">
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<!--
2+
doc/src/sgml/ref/set.sgml
3+
PostgreSQL documentation
4+
-->
5+
6+
<refentry id="SQL-PGPOOL-SET-CACHE">
7+
<indexterm zone="sql-pgpool-set-cache">
8+
<primary>PGPOOL SET</primary>
9+
</indexterm>
10+
11+
<refmeta>
12+
<refentrytitle>PGPOOL SET CACHE</refentrytitle>
13+
<manvolnum>1</manvolnum>
14+
<refmiscinfo>SQL - Language Statements</refmiscinfo>
15+
</refmeta>
16+
17+
<refnamediv>
18+
<refname>PGPOOL SET CACHE</refname>
19+
<refpurpose>delete query cache</refpurpose>
20+
</refnamediv>
21+
22+
<refsynopsisdiv>
23+
<synopsis>
24+
PGPOOL SET CACHE DELETE <replaceable class="PARAMETER">'query'</replaceable>
25+
</synopsis>
26+
</refsynopsisdiv>
27+
28+
<refsect1>
29+
<title>Description</title>
30+
31+
<para>
32+
The <command>PGPOOL SET CACHE DELETE</command> command deletes the
33+
<link linkend="runtime-in-memory-query-cache">query cache</link>
34+
previously created by the query. The query string must be exactly
35+
identical to the previous query, including
36+
trailing <literal>';'</literal>. Nevertheless if the query
37+
includes <literal>'</literal> (single quore), it needs to be
38+
prefixed by <literal>'</literal> like:
39+
<programlisting>
40+
PGPOOL SET CACHE DELETE 'SELECT ''FOO'';';
41+
</programlisting>
42+
This command is particularly useful for queries that are not
43+
invalidated by
44+
the <link linkend="guc-memqcache-auto-cache-invalidation">auto
45+
cache invalidation feature</link> because the query does not have
46+
any reference to tables.
47+
</para>
48+
<para>
49+
If you do not remember the previous query, you can
50+
use <xref linkend="PCP-INVALIDATE-QUERY-CACHE"> to delete all the
51+
query cache including the cache you want to delete. However it
52+
requires the <productname>Pgpool-II</productname> admin privilege.
53+
</para>
54+
<para>
55+
Upon successful deletion of the query cache, this command emits a
56+
notice message:
57+
<programlisting>
58+
NOTICE: query cache deleted. query: "<literal>query string</literal>"
59+
</programlisting>
60+
If the cache does not exist or query cache is not enabled, it emits
61+
a notice message:
62+
<programlisting>
63+
NOTICE: query cache does not exist for query: "<literal>query string</literal>"
64+
</programlisting>
65+
</para>
66+
</refsect1>
67+
68+
<refsect1>
69+
<title>Examples</title>
70+
71+
<para>
72+
Accidentally created an unwanted query cache. Delete it by using
73+
the command.
74+
<programlisting>
75+
test=# /*FORCE QUERY CACHE*/SELECT current_timestamp;
76+
current_timestamp
77+
-------------------------------
78+
2024-10-18 18:25:07.826423+09
79+
(1 row)
80+
81+
test=# PGPOOL SET CACHE DELETE '/*FORCE QUERY CACHE*/SELECT current_timestamp;';
82+
NOTICE: query cache deleted. query: "/*FORCE QUERY CACHE*/SELECT current_timestamp;"
83+
SET
84+
</programlisting>
85+
</para>
86+
87+
</refsect1>
88+
89+
<refsect1>
90+
<title>See Also</title>
91+
92+
<simplelist type="inline">
93+
<member><xref linkend="PCP-INVALIDATE-QUERY-CACHE"></member>
94+
</simplelist>
95+
</refsect1>
96+
97+
</refentry>

doc/src/sgml/reference.sgml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155

156156
&pgpoolShow
157157
&pgpoolSet
158+
&pgpoolSetCache
158159
&pgpoolReset
159160
&showPoolStatus
160161
&showPoolNodes

src/include/parser/nodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ typedef enum NodeTag
3434
/* pgpool Extension */
3535
T_PgpoolVariableSetStmt,
3636
T_PgpoolVariableShowStmt,
37+
T_PgpoolQueryCacheStmt,
3738
#include "nodetags.h"
3839
} NodeTag;
3940

src/include/query_cache/pool_memqcache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,4 +307,6 @@ extern void pool_init_whole_cache_blocks(void);
307307

308308
extern void clear_query_cache(void);
309309

310+
extern bool query_cache_delete_by_stmt(char *query, POOL_CONNECTION_POOL * backend);
311+
310312
#endif /* POOL_MEMQCACHE_H */

src/parser/gram.y

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,13 @@ VariableSetStmt:
16551655
n->is_local = false;
16561656
$$ = (Node *) n;
16571657
}
1658+
| PGPOOL set_rest_more
1659+
{
1660+
VariableSetStmt *n = $2;
1661+
n->type = T_PgpoolQueryCacheStmt; /* Hack to keep changes minimum */
1662+
n->is_local = false;
1663+
$$ = (Node *) n;
1664+
}
16581665
| SET set_rest
16591666
{
16601667
VariableSetStmt *n = $2;
@@ -1834,6 +1841,13 @@ set_rest_more: /* Generic SET syntaxes: */
18341841
n->args = list_make1(makeStringConst($3, @3));
18351842
$$ = n;
18361843
}
1844+
/* PGPOOL CACHE DELETE */
1845+
| SET CACHE DELETE_P Sconst
1846+
{
1847+
VariableSetStmt *n = makeNode(VariableSetStmt);
1848+
n->name = $4; /* query to delete query cache */
1849+
$$ = n;
1850+
}
18371851
;
18381852

18391853
var_name: ColId { $$ = $1; }

src/protocol/pool_proto_modules.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,20 @@ SimpleQuery(POOL_CONNECTION * frontend,
450450
pool_set_skip_reading_from_backends();
451451
return POOL_CONTINUE;
452452
}
453+
if (IsA(node, PgpoolQueryCacheStmt))
454+
{
455+
VariableSetStmt *vnode = (VariableSetStmt *) node;
453456

457+
if (query_cache_delete_by_stmt(vnode->name, backend))
458+
elog(NOTICE, "query cache deleted. query: \"%s\"", vnode->name);
459+
else
460+
elog(NOTICE, "query cache does not exist for query: \"%s\"", vnode->name);
461+
pool_ps_idle_display(backend);
462+
send_complete_and_ready(frontend, backend, "SET", -1);
463+
pool_query_context_destroy(query_context);
464+
pool_set_skip_reading_from_backends();
465+
return POOL_CONTINUE;
466+
}
454467
if (IsA(node, PgpoolVariableSetStmt))
455468
{
456469
VariableSetStmt *vnode = (VariableSetStmt *) node;

0 commit comments

Comments
 (0)