From: 王旭 <wangxu@gu360.com>
To: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: Issue related with patitioned table:How can I quickly determine which child table my record is in,given a specific primary key value?
Date: Wed, 17 Jul 2019 15:18:41 +0800
Message-ID: <tencent_267C505771F9162A6E330836@qq.com> (raw)
Hello!
My table is described as below:
################
CREATE TABLE IF NOT EXISTS mytable
(
uuid varchar(45) NOT NULL,
symbol_id smallint NOT NULL,
...
...
PRIMARY KEY (symbol_id,uuid)
) partition by hash(symbol_id)
create table mytable_0 partition of 0 FOR VALUES WITH (MODULUS 3, REMAINDER 0);
create table mytable_1 partition of 1 FOR VALUES WITH (MODULUS 3, REMAINDER 1);
create table mytable_2 partition of 2 FOR VALUES WITH (MODULUS 3, REMAINDER 2);
################
I understand that I can find the specific child table using explain.But is there any simpler way
in which I can get the name of child table via a specific symbol_id value,so that I can use it to
execute query on child table instead of on partition master table?
I tried something like this: e.g., for symbol_id 6365,
SELECT (hashint2(6365::SMALLINT)% 10)
But the result doesn't make any sense,cannot be used to determine which child table(mytable_0,mytable_1,mytable_2) my record is in.
The reason is that my frequent query doesn't need primary key(the query is on some other index),so query on a specific child table would
give me much more improvement on performance(Query would execute without loading the primary key index at all).
Is there any simple function to do this job? Can someone help me on this?
Many Thanks,
James.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: wangxu@gu360.com
Subject: Re: Issue related with patitioned table:How can I quickly determine which child table my record is in,given a specific primary key value?
In-Reply-To: <tencent_267C505771F9162A6E330836@qq.com>
References: <tencent_267C505771F9162A6E330836@qq.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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