[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgresql-hackers
Subject:    =?UTF-8?B?5Zue5aSN77yaUmU6IFJlZ2FyZGluZyB0aGUgbmVjZXNzaXR5IG9mIFJlbGF0aW9uR2V0TnVt?= =?UTF-8?B?YmVyT
From:       "=?UTF-8?B?6ZmI5L2z5piVKOatpeecnyk=?=" <buzhen.cjx () alibaba-inc ! com>
Date:       2021-05-31 5:59:27
Message-ID: be2adb04-82e4-4e76-8a26-f3166cc631c7.buzhen.cjx () alibaba-inc ! com
[Download RAW message or body]

[Attachment #2 (text/plain)]

+1,  This would be an nice improvement even the lseek is fast usually, it is a system call after all

Buzhen------------------------------------------------------------------
发件人:Andy Fan<zhihui.fan1213@gmail.com>
日 期:2021年05月31日 13:46:22
收件人:PostgreSQL Hackers<pgsql-hackers@lists.postgresql.org>
主 题:Re: Regarding the necessity of RelationGetNumberOfBlocks for every rescan / bitmap heap scan.



On Sat, May 29, 2021 at 11:23 AM Andy Fan <zhihui.fan1213@gmail.com> wrote:

Hi: 

I'm always confused about the following codes.

static void
initscan(HeapScanDesc scan, ScanKey key, bool keep_startblock)
{
 ParallelBlockTableScanDesc bpscan = NULL;
 bool allow_strat;
 bool allow_sync;

 /*
 * Determine the number of blocks we have to scan.
 *
 * It is sufficient to do this once at scan start, since any tuples added
 * while the scan is in progress will be invisible to my snapshot anyway.
 * (That is not true when using a non-MVCC snapshot.  However, we couldn't
 * guarantee to return tuples added after scan start anyway, since they
 * might go into pages we already scanned.  To guarantee consistent
 * results for a non-MVCC snapshot, the caller must hold some higher-level
 * lock that ensures the interesting tuple(s) won't change.)
 */
 if (scan->rs_base.rs_parallel != NULL)
 {
 bpscan = (ParallelBlockTableScanDesc) scan->rs_base.rs_parallel;
 scan->rs_nblocks = bpscan->phs_nblocks;
 }
 else
 scan->rs_nblocks = RelationGextNumberOfBlocks(scan->rs_base.rs_rd);


..
}

1. Why do we need scan->rs_nblocks =
   RelationGextNumberOfBlocks(scan->rs_base.rs_rd) for every rescan, which looks
   mismatched with the comments along the code. and the comments looks
   reasonable to me.

To be more precise, this question can be expressed as if the relation size
can be changed during rescan. We are sure that the size can be increased due to
new data, but we are sure that the new data is useless for the query as well. So
looks this case is ok. and for the file size decreasing, since we have lock on
the relation, so the file size would not be reduced as well (I have verified
this logic on the online vacuum case, other cases should be similar as well).


-- 
Best Regards
Andy Fan (https://www.aliyun.com/) 

[Attachment #3 (text/html)]

<div id="mailbox-conversation" \
style="color:#494F50;font-size:14.000000px;font-family:'Helvetica \
Neue'"><div>+1,&nbsp;&nbsp;This&nbsp;would&nbsp;be&nbsp;an&nbsp;nice&nbsp;improvement& \
nbsp;even&nbsp;the&nbsp;lseek&nbsp;is&nbsp;fast&nbsp;usually,&nbsp;it&nbsp;is&nbsp;a&n \
bsp;system&nbsp;call&nbsp;after&nbsp;all</div><div><span><br></span></div><div><div><span \
style="caret-color: #000000;color: #000000;font-family: 微软雅黑;font-size: \
14.0px;font-style: normal;font-variant-caps: normal;font-weight: \
normal;letter-spacing: normal;orphans: auto;text-align: start;text-indent: \
0.0px;text-transform: none;white-space: normal;widows: 2;word-spacing: \
0.0px;-webkit-text-size-adjust: auto;-webkit-text-stroke-width: \
0.0px;background-color: #ffffff;text-decoration: none;display: inline;float: \
none;">Buzhen</span></div></div></div><blockquote>------------------------------------------------------------------<br \
/>发件人:Andy Fan&lt;zhihui.fan1213@gmail.com&gt;<br />日 期:2021年05月31日 13:46:22<br \
/>收件人:PostgreSQL Hackers&lt;pgsql-hackers@lists.postgresql.org&gt;<br />主 题:Re: \
Regarding the necessity of RelationGetNumberOfBlocks for every rescan / bitmap heap \
scan.<br /><br /><div dir="ltr"><div dir="ltr"><br></div><br><div \
class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, May 29, 2021 at 11:23 \
AM Andy Fan &lt;<a href="mailto:zhihui.fan1213@gmail.com">zhihui.fan1213@gmail.com</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi: \
<br><br>I&#39;m always confused about the following codes.<br><br>static \
void<br>initscan(HeapScanDesc scan, ScanKey key, bool \
keep_startblock)<br>{<br>	ParallelBlockTableScanDesc bpscan = \
NULL;<br>	bool		allow_strat;<br>	bool		allow_sync;<br><br>	/*<br>	 * Determine the \
number of blocks we have to scan.<br>	 *<br>	 * It is sufficient to do this once at \
scan start, since any tuples added<br>	 * while the scan is in progress will be \
invisible to my snapshot anyway.<br>	 * (That is not true when using a non-MVCC \
snapshot.  However, we couldn&#39;t<br>	 * guarantee to return tuples added after \
scan start anyway, since they<br>	 * might go into pages we already scanned.  To \
guarantee consistent<br>	 * results for a non-MVCC snapshot, the caller must hold \
some higher-level<br>	 * lock that ensures the interesting tuple(s) won&#39;t \
change.)<br>	 */<br>	if (scan-&gt;rs_base.rs_parallel != NULL)<br>	{<br>		bpscan = \
(ParallelBlockTableScanDesc) scan-&gt;rs_base.rs_parallel;<br>		scan-&gt;rs_nblocks = \
bpscan-&gt;phs_nblocks;<br>	}<br>	else<br>		scan-&gt;rs_nblocks = \
RelationGextNumberOfBlocks(scan-&gt;rs_base.rs_rd);<br><br><br>..<br>}<br><br>1. Why \
do we need scan-&gt;rs_nblocks =<br>   \
RelationGextNumberOfBlocks(scan-&gt;rs_base.rs_rd) for every rescan, which looks<br>  \
mismatched with the comments along the code. and the comments looks<br>   reasonable \
to me.<br></div></blockquote><div><br></div>To be more precise, this question can be \
expressed as if the relation size<br>can be changed during rescan. We are sure that \
the size can be increased due to<br>new data, but we are sure that the new data is \
useless for the query as well. So<br>looks this case is ok. and for the file size \
decreasing, since we have lock on<br>the relation, so the file size would not be \
reduced as well (I have verified<br><div>this logic on the online vacuum case, other \
cases should be similar as well).</div><div><br></div></div><div><br></div>-- \
<br><div dir="ltr" class="gmail_signature"><div dir="ltr">Best Regards<div>Andy Fan \
(<a href="https://www.aliyun.com/" \
target="_blank">https://www.aliyun.com/</a>)</div></div></div></div> \
<br></blockquote>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic