Re: [HACKERS] BRIN INDEX value

2015-09-04 Thread Amit Langote
On Saturday, September 5, 2015, Tatsuo Ishii wrote: > > Tatsuo Ishii wrote: > >> > On 9/4/2015 2:04 PM, Tatsuo Ishii wrote: > >> >>> One thing I imagine we could do is to change the signature of > >> >>> summrize_range() to also include heapNumBlks which its (only) caller > >> >>> brinsummarize()

Re: [HACKERS] BRIN INDEX value

2015-09-04 Thread Tatsuo Ishii
> Tatsuo Ishii wrote: >> > On 9/4/2015 2:04 PM, Tatsuo Ishii wrote: >> >>> One thing I imagine we could do is to change the signature of >> >>> summrize_range() to also include heapNumBlks which its (only) caller >> >>> brinsummarize() already computes. It will look like: >> >>> >> >>> static void

Re: [HACKERS] BRIN INDEX value

2015-09-04 Thread Alvaro Herrera
Tatsuo Ishii wrote: > > On 9/4/2015 2:04 PM, Tatsuo Ishii wrote: > >>> One thing I imagine we could do is to change the signature of > >>> summrize_range() to also include heapNumBlks which its (only) caller > >>> brinsummarize() already computes. It will look like: > >>> > >>> static void summariz

Re: [HACKERS] BRIN INDEX value

2015-09-04 Thread Tatsuo Ishii
> On Fri, Sep 4, 2015 at 10:03 AM, Tatsuo Ishii wrote: >> >> I have looked into your patch and am a little bit worried because it >> calls RelationGetNumberOfBlocks() which is an expensive function. >> I think there are two ways to avoid it. >> >> 1) fall back to your former patch. However it may

Re: [HACKERS] BRIN INDEX value

2015-09-04 Thread Amit Kapila
On Fri, Sep 4, 2015 at 10:03 AM, Tatsuo Ishii wrote: > > I have looked into your patch and am a little bit worried because it > calls RelationGetNumberOfBlocks() which is an expensive function. > I think there are two ways to avoid it. > > 1) fall back to your former patch. However it may break ex

Re: [HACKERS] BRIN INDEX value

2015-09-03 Thread Tatsuo Ishii
> On 9/4/2015 2:04 PM, Tatsuo Ishii wrote: >>> One thing I imagine we could do is to change the signature of >>> summrize_range() to also include heapNumBlks which its (only) caller >>> brinsummarize() already computes. It will look like: >>> >>> static void summarize_range(IndexInfo *indexInfo, Br

Re: [HACKERS] BRIN INDEX value

2015-09-03 Thread Amit Langote
On 9/4/2015 2:04 PM, Tatsuo Ishii wrote: >> One thing I imagine we could do is to change the signature of >> summrize_range() to also include heapNumBlks which its (only) caller >> brinsummarize() already computes. It will look like: >> >> static void summarize_range(IndexInfo *indexInfo, BrinBuild

Re: [HACKERS] BRIN INDEX value

2015-09-03 Thread Tatsuo Ishii
> One thing I imagine we could do is to change the signature of > summrize_range() to also include heapNumBlks which its (only) caller > brinsummarize() already computes. It will look like: > > static void summarize_range(IndexInfo *indexInfo, BrinBuildState *state, >

Re: [HACKERS] BRIN INDEX value

2015-09-03 Thread Amit Langote
On 9/4/2015 1:33 PM, Tatsuo Ishii wrote: >> Ah, it did cross my mind to the fix it in brin.c but was not sure. I did >> it that way in the attached patch. > > Amit, > > I have looked into your patch and am a little bit worried because it > calls RelationGetNumberOfBlocks() which is an expensive f

Re: [HACKERS] BRIN INDEX value

2015-09-03 Thread Tatsuo Ishii
> On 9/4/2015 8:28 AM, Tatsuo Ishii wrote: >>> >>> Attached hack fixes the symptom but perhaps not the correct fix for this. >> >> Why can't we fix summarize_range() in brin.c: >> >> IndexBuildHeapRangeScan(heapRel, state->bs_irel, indexInfo, false, true, >>

Re: [HACKERS] BRIN INDEX value

2015-09-03 Thread Amit Langote
On 9/4/2015 12:01 PM, Alvaro Herrera wrote: > Amit Langote wrote: >> On 9/4/2015 9:22 AM, Tatsuo Ishii wrote: >>> >>> 3) I wonder if other index type is suffered by this type of bug. >>> >> >> About 3, it seems unlikely. Both the IndexBuildHeapRangeScan() and >> heap_setscanlimits() were introduced

Re: [HACKERS] BRIN INDEX value

2015-09-03 Thread Alvaro Herrera
Amit Langote wrote: > On 9/4/2015 9:22 AM, Tatsuo Ishii wrote: > >> > >> In this case, scan->rs_startblock is 384 set by IndexBuildHeapRangeScan() > >> using heap_setscanlimits(). One can imagine how the above heap finish > >> criteria might not work as expected. > > > > What scares me is: > > >

Re: [HACKERS] BRIN INDEX value

2015-09-03 Thread Amit Langote
On 9/4/2015 8:28 AM, Tatsuo Ishii wrote: >> >> Attached hack fixes the symptom but perhaps not the correct fix for this. > > Why can't we fix summarize_range() in brin.c: > > IndexBuildHeapRangeScan(heapRel, state->bs_irel, indexInfo, false, true, >

Re: [HACKERS] BRIN INDEX value

2015-09-03 Thread Amit Langote
On 9/4/2015 9:22 AM, Tatsuo Ishii wrote: >> >> In this case, scan->rs_startblock is 384 set by IndexBuildHeapRangeScan() >> using heap_setscanlimits(). One can imagine how the above heap finish >> criteria might not work as expected. > > What scares me is: > > 1) the bug will not be found unless

Re: [HACKERS] BRIN INDEX value

2015-09-03 Thread Tatsuo Ishii
> The summarization during VACUUM invokes IndexBuildHeapRangeScan() which is > passed scanStartBlock and scanNumBlocks. If scanStartBlock + scanNumBlocks >> heapTotalBlocks, further down the line, heapgettup() may start returning > tuples from the beginning given the following code in it: > > pa

Re: [HACKERS] BRIN INDEX value

2015-09-03 Thread Tatsuo Ishii
> The summarization during VACUUM invokes IndexBuildHeapRangeScan() which is > passed scanStartBlock and scanNumBlocks. If scanStartBlock + scanNumBlocks >> heapTotalBlocks, further down the line, heapgettup() may start returning > tuples from the beginning given the following code in it: > > pa

Re: [HACKERS] BRIN INDEX value

2015-09-03 Thread Amit Langote
On 9/3/2015 5:49 PM, Tatsuo Ishii wrote: > > However I inserted data *after* creating index, the value is > different. > VACUUM; > VACUUM > SELECT * FROM brin_revmap_data(get_raw_page('brinidx', 1)) WHERE pages != > '(0,0)'::tid; > pages > --- > (2,1) > (2,2) > (2,3) > (2,4) > (4 rows)

[HACKERS] BRIN INDEX value

2015-09-03 Thread Tatsuo Ishii
When creating a brin index, it shows an interesting behavior when used with VACUUM. First, I created a brin index after inserting data. === DROP TABLE t1; DROP TABLE CREATE TABLE t1(i int); CREATE TABLE INSERT INTO t1 VALUES (generate_ser