pg.ddx.io pgsql-general@postgresql.org mailing list archivehelp / color / mirror / Atom feed
Lock acquisition for partition table when setting generic plan 2+ messages / 2 participants [nested] [flat]
* Lock acquisition for partition table when setting generic plan @ 2020-01-15 02:58 yotsunaga.naoki@fujitsu.com <yotsunaga.naoki@fujitsu.com> 2020-01-15 15:09 ` Re: Lock acquisition for partition table when setting generic plan Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 1 reply; 2+ messages in thread From: yotsunaga.naoki@fujitsu.com @ 2020-01-15 02:58 UTC (permalink / raw) To: pgsql-general Hi all, I have a question. I did the following. Even though I accessed one partition table(test2 table), I also acquired locks on other partition tables(test1 table). I expected to acquire locks on the parent table(test table) and the partition table to access(test2 table). Why does this happen? At the first execution, to create a generic plan, I thought it was accessing all partition tables. However, the following event occur after second time too. * Only occurs when plan_cache_mode = force_generic_plan. postgres=# create table test(id int) partition by range (id); CREATE TABLE postgres=# create table test1 partition of test for values from (1) to (2); CREATE TABLE postgres=# create table test2 partition of test for values from (2) to (3); CREATE TABLE postgres=# prepare hoge(int) as select * from test where id = $1; PREPARE postgres=# set plan_cache_mode = force_generic_plan ; SET postgres=# begin; BEGIN postgres=# execute hoge(2); id ---- (0 rows) postgres=# SELECT l.pid,l.granted,d.datname,l.locktype,relation,relation::regclass,transactionid,l.mode FROM pg_locks l LEFT JOIN pg_database d ON l.database = d.oid WHERE l.pid != pg_backend_pid() ORDER BY l.pid; pid | granted | datname | locktype | relation | relation | transactionid | mode -------+---------+----------+------------+----------+----------+---------------+----------------- 16921 | t | postgres | relation | 16562 | test2 | | AccessShareLock 16921 | t | postgres | relation | 16559 | test1 | | AccessShareLock 16921 | t | postgres | relation | 16556 | test | | AccessShareLock 16921 | t | | virtualxid | | | | ExclusiveLock (4 rows) Regards Naoki Yotsunaga ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Lock acquisition for partition table when setting generic plan 2020-01-15 02:58 Lock acquisition for partition table when setting generic plan yotsunaga.naoki@fujitsu.com <yotsunaga.naoki@fujitsu.com> @ 2020-01-15 15:09 ` Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 2+ messages in thread From: Tom Lane @ 2020-01-15 15:09 UTC (permalink / raw) To: yotsunaga.naoki@fujitsu.com <yotsunaga.naoki@fujitsu.com>; +Cc: pgsql-general "yotsunaga.naoki@fujitsu.com" <yotsunaga.naoki@fujitsu.com> writes: > I did the following. > Even though I accessed one partition table(test2 table), I also acquired locks on other partition tables(test1 table). > I expected to acquire locks on the parent table(test table) and the partition table to access(test2 table). > Why does this happen? You specified a generic plan: > postgres=# set plan_cache_mode = force_generic_plan ; so you are not going to get any plan-time optimization based on knowing the id parameter. Therefore the plan must include sub-plan nodes for every child table, so executing it requires locking all those tables to make sure their schemas haven't changed. regards, tom lane ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2020-01-15 15:09 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2020-01-15 02:58 Lock acquisition for partition table when setting generic plan yotsunaga.naoki@fujitsu.com <yotsunaga.naoki@fujitsu.com> 2020-01-15 15:09 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox