Re: Fix for parallel BTree initialization bug

From: Justin Pryzby <pryzby(at)telsasoft(dot)com>
To: "Jameson, Hunter 'James'" <hunjmes(at)amazon(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org, Robert Haas <rhaas(at)postgresql(dot)org>, Rahila Syed <rahila(dot)syed(at)2ndquadrant(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Subject: Re: Fix for parallel BTree initialization bug
Date: 2020-09-11 02:37:28
Message-ID: 20200911023728.GK18552@telsasoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Against all odds, I was able to reproduce this.

begin;
CREATE TABLE t AS SELECT generate_series(1,999999)i;
ALTER TABLE t SET (parallel_workers=2, autovacuum_enabled=off);
CREATE INDEX ON t(i);
commit;

SET parallel_leader_participation=off; SET min_parallel_table_scan_size=0; SET enable_bitmapscan=off; SET enable_indexonlyscan=off; SET enable_seqscan=off;
explain(analyze , verbose on) SELECT COUNT(1) FROM t a WHERE a.i>555 AND i IN ( 333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,427,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447,448,449,450,451,452,453,454,455,456,457,458,459,460,461,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,497,498,499,500,501,502,503,504,505,506,507,508,509,510,511,512,513,514,515,516,517,518,519,520,521,522,523,524,525,526,527,528,529,530,531,532,533,534,535,536,537,538,539,540,541,542,543,544,545,546,547,548,549,550,551,552,553,554,555,556,557,558,559,560,561,562,563,564,565,566,567,568,569,570,571,572,573,574,575,576,577,578,579,580,581,582,583,584,585,586,587,588,589,590,591,592,593,594,595,596,597,598,599,600,601,602,603,604,605,606,607,608,609,610,611,612,613,614,615,616,617,618,619,620,621,622,623,624,625,626,627,628,629,630,631,632,633,634,635,636,637,638,639,640,641,642,643,644,645,646,647,648,649,650,651,652,653,654,655,656,657,658,659,660,661,662,663,664,665,666 ) ORDER BY 1;

Which gives a plan like:
Sort (cost=5543.71..5543.72 rows=1 width=8)
Sort Key: (count(1))
-> Finalize Aggregate (cost=5543.69..5543.70 rows=1 width=8)
-> Gather (cost=5543.48..5543.69 rows=2 width=8)
Workers Planned: 2
-> Partial Aggregate (cost=4543.48..4543.49 rows=1 width=8)
-> Parallel Index Scan using t_i_idx on t a (cost=0.42..4204.92 rows=135423 width=0)

I don't get an error, on read-only hot standby. I do get inconsistent results,
including on primary server.

count | 222
count | 214

This appears to be a bug in commit 569174f1b btree: Support parallel index scans.

I've added your patch here:
https://commitfest.postgresql.org/30/2729/

In the course of reproducing this, I also added:
@@ -1972,2 +1975,3 @@ _bt_readnextpage(IndexScanDesc scan, BlockNumber blkno, ScanDirection dir)
rel = scan->indexRelation;
+ Assert(BlockNumberIsValid(blkno));

--
Justin

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2020-09-11 02:40:06 Re: SIGQUIT handling, redux
Previous Message Peter Smith 2020-09-11 01:43:34 Re: Implement UNLOGGED clause for COPY FROM