From: | Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com> |
---|---|
To: | Masayuki Takahashi <masayuki038(at)gmail(dot)com> |
Cc: | Pg Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: How to estimate the shared memory size required for parallel scan? |
Date: | 2018-08-17 00:27:53 |
Message-ID: | CAEepm=0hPT+TV1394LuciO+nY7ZkXon0oarg=M3B56ZhSR3t3A@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Thu, Aug 16, 2018 at 11:36 PM, Masayuki Takahashi
<masayuki038(at)gmail(dot)com> wrote:
> I am trying to change cstore_fdw to scan in parallel. FDW interface provide
> 'EstimateDSMForeignScan' for required shared memory size to scan in parallel.
>
> How to estimate the shared memory size required for parallel scan?
It's a slightly strange use of the word "estimate". It means "tell me
how much shared memory you need". Later, your
InitializeDSMForeignScan() callback will receive a pointer to exactly
that much shared memory to initialise. Then
InitializeWorkerForeignScan will also receive a pointer to that
memory, inside every worker process. Note that it may be mapped at a
different address in each process, so be careful not to use raw
pointers. It's up to you to design a struct to hold whatever data,
spinlocks, LWLocks, atomics etc you might need to orchestrate your
parallel scan.
It works much the same way for built-in executor nodes that are
parallel-aware by the way. For example, ExecHashJoinEstimate()
reserves sizeof(ParallelHashJoinState), and then in
ExecHashJoinInitializeDSM() it allocates and initialises it, and
ExecHashJoinIntializeWorker() tells the workers about it. The
built-in executor nodes have to do a little bit more work than FDWs,
using the plan node ID to allocate and look things up in a "TOC"
(table of contents), but nodeForeignScan.c does that work for you in
your case: it just asks you how much you want, and then gives it to
you.
--
Thomas Munro
http://www.enterprisedb.com
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 2018-08-17 01:31:27 | Re: Facility for detecting insecure object naming |
Previous Message | Tom Lane | 2018-08-16 23:37:42 | Re: has_table_privilege for a table in unprivileged schema causes an error |