Re: Parallel bitmap heap scan
Dilip Kumar <dilipbalaut@gmail.com>
From: Dilip Kumar <dilipbalaut@gmail.com>
To: Robert Haas <robertmhaas@gmail.com>
Cc: Thomas Munro <thomas.munro@enterprisedb.com>, Haribabu Kommi <kommi.haribabu@gmail.com>,
Rafia Sabih <rafia.sabih@enterprisedb.com>, tushar <tushar.ahuja@enterprisedb.com>,
Amit Khandekar <amitdkhan.pg@gmail.com>, Amit Kapila <amit.kapila16@gmail.com>, Andres Freund <andres@anarazel.de>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2017-02-27T05:00:49Z
Lists: pgsql-hackers
On Sun, Feb 26, 2017 at 9:26 PM, Robert Haas <robertmhaas@gmail.com> wrote: Thanks for the review, I will work on these. There are some comments I need suggestions. > tbm_free_shared_area because the two iterators share one copy of the > underlying iteration arrays, and the TBM code isn't smart enough to > avoid freeing them twice. You're going to have to come up with a > better solution to that problem; nodeBitmapHeapScan.c shouldn't know > about the way the underlying storage details are managed. (Maybe you > need to reference-count the iterator arrays?) Yeah, I also think current way doesn't look so clean, currently, these arrays are just integers array, may be we can use a first slot of the array for reference-count? or convert to the structure which has space for reference-count and an integers array. What do you suggest? > > + if (node->inited) > + goto start_iterate; > > My first programming teacher told me not to use goto. I've > occasionally violated that rule, but I need a better reason than you > have here. It looks very easy to avoid. Yes, this can be avoided, I was just trying to get rid of multi-level if nesting and end up with the "goto". > > + pbms_set_parallel(outerPlanState(node)); > > I think this should be a flag in the plan, and the planner should set > it correctly, instead of having it be a flag in the executor that the > executor sets. Also, the flag itself should really be called > something that involves the word "shared" rather than "parallel", > because the bitmap will not be created in parallel, but it will be > shared. Earlier, I thought that it will be not a good idea to set that flag in BitmapIndexScan path because the same path can be used either under ParallelBitmapHeapPath or under normal BitmapHeapPath. But, now after putting some thought, I realised that we can do that in create_plan. Therefore, I will change this. > > Have you checked whether this patch causes any regression in the > non-parallel case? It adds a bunch of "if" statements, so it might. > Hopefully not, but it needs to be carefully tested. During the initial patch development, I have tested this aspect also but never published any results for the same. I will do that along with my next patch and post the results. > > pbms_is_leader() looks horrifically inefficient. Every worker will > reacquire the spinlock for every tuple. You should only have to enter > this spinlock-acquiring loop for the first tuple. After that, either > you became the leader, did the initialization, and set the state to > PBM_FINISHED, or you waited until the pre-existing leader did the > same. You should have a backend-local flag that keeps you from > touching the spinlock for every tuple. I wouldn't be surprised if > fixing this nets a noticeable performance increase for this patch at > high worker counts. I think there is some confusion, if you notice, below code will avoid calling pbms_is_leader for every tuple. It will be called only first time. And, after that node->inited will be true and it will directly jump to start_iterate for subsequent calls. Am I missing something? > + if (node->inited) > + goto start_iterate; -- Regards, Dilip Kumar EnterpriseDB: http://www.enterprisedb.com
Commits
-
Pass DSA_ALLOC_HUGE when allocating a shared TIDBitmap.
- a171f01501e1 10.0 landed
-
Support parallel bitmap heap scans.
- f35742ccb7aa 10.0 landed
-
tidbitmap: Support shared iteration.
- 98e6e89040a0 10.0 landed
-
Shut down Gather's children before shutting down Gather itself.
- acf555bc53ac 10.0 landed
-
Revise the way the element allocator for a simplehash is specified.
- c3c4f6e1740b 10.0 cited
-
Refactor bitmap heap scan estimation of heap pages fetched.
- da08a6598973 10.0 landed
-
Use more efficient hashtable for tidbitmap.c to speed up bitmap scans.
- 75ae538bc316 10.0 cited