<div dir="auto"><div><br><div class="gmail_extra"><br><div class="gmail_quote">On May 17, 2017 05:15, &quot;Tatsuo Ishii&quot; &lt;<a href="mailto:ishii@sraoss.co.jp">ishii@sraoss.co.jp</a>&gt; wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="elided-text">&gt; Hi all,<br>
&gt;<br>
&gt; I&#39;m using pgpool-ii 3.5.4, with Postgres 9.4.<br>
&gt;<br>
&gt; pgpool --version<br>
&gt; pgpool-II version 3.5.4 (ekieboshi)<br>
&gt;<br>
&gt; I need to *only* cache queries to one table, because this pgpool sees only<br>
&gt; some of the queries. So I want to be safe, and only cache the tables I<br>
&gt; *know* are safe (mainly some read-only parameters). This pool is in a<br>
&gt; remote location, next to the replica slave, but with high latency to the<br>
&gt; master.<br>
&gt;<br>
&gt; I set:<br>
&gt;<br>
&gt; white_memqcache_table_list = &#39;table_to_cache&#39;<br>
&gt; black_memqcache_table_list = &#39;.*&#39;<br>
&gt;<br>
&gt; However, pgpool *never* caches queries to the &quot;table_to_cache&quot;.<br>
&gt;<br>
&gt; I went to have a look at the source, function pool_is_allow_to_cache, in:<br>
&gt;<br>
&gt; <a href="https://github.com/pgpool/pgpool2/blob/V3_5_4_RPM/src/query_cache/pool_memqcache.c" rel="noreferrer" target="_blank">https://github.com/pgpool/<wbr>pgpool2/blob/V3_5_4_RPM/src/<wbr>query_cache/pool_memqcache.c</a><br>
&gt;<br>
&gt; line 785: bool pool_is_allow_to_cache(Node *node, char *query)<br>
&gt;<br>
&gt; line 799: if (pool_config-&gt;num_black_<wbr>memqcache_table_list &gt; 0)<br>
&gt;<br>
&gt; if (pool_is_table_in_black_list(<wbr>ctx.table_names[i]) == true)<br>
&gt; {<br>
&gt; ereport(DEBUG1,<br>
&gt; (errmsg(&quot;memcache: node is not allowed to cache&quot;)));<br>
&gt; return false;<br>
&gt; }<br>
&gt;<br>
&gt; line 861: if (pool_config-&gt;num_white_<wbr>memqcache_table_list &gt; 0)<br>
&gt;<br>
&gt; if (pool_is_table_in_white_list(<wbr>table) == false)<br>
&gt; {<br>
&gt; ereport(DEBUG1,<br>
&gt; (errmsg(&quot;memcache: node is not allowed to cache&quot;)));<br>
&gt; return false;<br>
&gt; }<br>
&gt;<br>
&gt; This tells me that, if the table_to_cache matches the black list, it will<br>
&gt; never reach the part where it will try to match the white list.<br>
&gt;<br>
&gt; If I don&#39;t set the blacklist, then pgpool caches some tables that have high<br>
&gt; churn, and gets stale values.<br>
&gt;<br>
&gt; I found this nice slide set by Tatsuo Ishii,<br>
&gt; <a href="https://www.sraoss.co.jp/event_seminar/2012/20121024_pgpool-II_pgconfEU2012_sraoss.pdf" rel="noreferrer" target="_blank">https://www.sraoss.co.jp/<wbr>event_seminar/2012/20121024_<wbr>pgpool-II_pgconfEU2012_sraoss.<wbr>pdf</a><br>
&gt; ,<br>
&gt; whose page 8 (When pgpool does not create cache) ends with this bullet<br>
&gt; point:<br>
&gt;<br>
</div>&gt;    - Tables listed in  “white_memqcache_table_list” will be cached even<br>
<div class="quoted-text">&gt;    above conditions are met<br>
&gt;<br>
&gt; It seems the above function was changed two months after the slide set&#39;s<br>
&gt; date, in commit<br>
&gt;<br>
&gt; <a href="https://github.com/pgpool/pgpool2/commit/41febb3aaa4480e0c9219e4538e04ef7398669a6" rel="noreferrer" target="_blank">https://github.com/pgpool/<wbr>pgpool2/commit/<wbr>41febb3aaa4480e0c9219e4538e04e<wbr>f7398669a6</a><br>
&gt;<br>
&gt;        Fix bug that only tables in white_memqcache_table_list was cached<br>
&gt;<br>
&gt; which split a function named pool_is_table_to_cache into two functions<br>
&gt; pool_is_table_in_black_list and pool_is_table_in_white_list, and this broke<br>
&gt; the above behaviour.<br>
&gt;<br>
&gt; Am I right in this analysis? Is this a bug? I can&#39;t find in the docs any<br>
&gt; mention of priority between these black and white lists, so, have I<br>
&gt; stumbled upon undefined behaviour?<br>
<br>
</div>I have looked into this and found that the behavior of the program<br>
has never been same as descibed in:<br>
<a href="https://www.sraoss.co.jp/event_seminar/2012/20121024_pgpool-II_pgconfEU2012_sraoss.pdf" rel="noreferrer" target="_blank">https://www.sraoss.co.jp/<wbr>event_seminar/2012/20121024_<wbr>pgpool-II_pgconfEU2012_sraoss.<wbr>pdf</a><br>
Sorry for this.<br>
<br>
So the commit:<br>
<a href="https://github.com/pgpool/pgpool2/commit/41febb3aaa4480e0c9219e4538e04ef7398669a6" rel="noreferrer" target="_blank">https://github.com/pgpool/<wbr>pgpool2/commit/<wbr>41febb3aaa4480e0c9219e4538e04e<wbr>f7398669a6</a><br>
actually did not break the the behavior.<br>
<br>
Here is the correct description of the current behavior of the code:<br>
<br>
1) Check black_memqcache_table_list. If the target table name matches<br>
any of the entries, the table is not cached. Done.<br>
<br>
2) If the table is one of:<br>
<br>
   SELECTs including views<br>
   SELECTs including non immutable functions<br>
   SELECTs including temp tables, unlogged tables<br>
   SELECT result is too large (memqcache_maxcache)<br>
   SELECT FOR SHARE/UPDATE<br>
   SELECT starting with &quot;/*NO QUERY CACHE*/&quot; comment<br>
   SELECT including system catalogs<br>
   SELECT uses TABLESAMPLE<br>
<br>
   then the table is not cached. Go to step 3.<br>
<br>
3) If white_memqcache_table_list is not empty and the table is either<br>
VIEW or unlogged table, and the table name matches any of the entries<br>
of white_memqcache_table_list, then the table is cached. If not, the<br>
table is not cached. Done.<br>
<br>
4) Other tables are cached even if they are not listed in<br>
white_memqcache_table_list.<br>
<br>
So to satify your request, following method can be used.<br>
<br>
1) Keep white_memqcache_table_list empty.<br>
<br>
2) Add a regular expression which means &quot;except table_to_cache&#39; to<br>
black_memqcache_table_list. For example if you want to cache &#39;t1&#39;, you<br>
can use following regular expression.<br>
<br>
black_memqcache_table_list = &#39;(([^1]|[^t]1)|[^t]t)+&#39;<br>
<br>
This is pretty confusing but it works.<br>
<br>
Best regards,<br>
--<br>
Tatsuo Ishii<br>
SRA OSS, Inc. Japan<br>
English: <a href="http://www.sraoss.co.jp/index_en.php" rel="noreferrer" target="_blank">http://www.sraoss.co.jp/index_<wbr>en.php</a><br>
Japanese:<a href="http://www.sraoss.co.jp" rel="noreferrer" target="_blank">http://www.sraoss.co.<wbr>jp</a><br>
</blockquote></div><br></div></div><div class="gmail_extra" dir="auto">Thanks for your feedback. </div><div class="gmail_extra" dir="auto"><br></div><div class="gmail_extra" dir="auto">I came to the same conclusion yesterday, and stuck till 2 am trying to create a regexp with a negative match for the black list.</div><div class="gmail_extra" dir="auto"><br></div><div class="gmail_extra" dir="auto">Tried with ^((?!(t1|t2)$).+$, but this syntax was not accepted by the re library pgpool uses -- I guess you use the pcre lib on your (<a href="http://pgpool.net">pgpool.net</a>&#39;s) yum repo for rhel7, based on ldd output. </div><div class="gmail_extra" dir="auto"><br></div><div class="gmail_extra" dir="auto">I&#39;ll try to find out exactly what kind of syntax that regexp lib use, if any, otherwise I will follow your suggestion,  although that feels like a an unmaintenable mess in the long run. </div><div class="gmail_extra" dir="auto"><br></div><div class="gmail_extra" dir="auto">Regards, </div><div class="gmail_extra" dir="auto">-José Pedro </div><div class="gmail_extra" dir="auto"><br></div><div class="gmail_extra" dir="auto">PS: I am impressed with the level of detail you managed to provide in your  response</div></div>