pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: James(王旭) <wangxu@gu360.com>
To: Luca Ferrari <fluca1978@gmail.com>
Cc: pgsql-general <pgsql-general@lists.postgresql.org>
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?
Date: Wed, 17 Jul 2019 18:59:35 +0800
Message-ID: <tencent_10CD0FFC540E29992BA299BA@qq.com> (raw)
In-Reply-To: <CAKoxK+4iRo1V+EJGKSgCjqutwjdLDsFghi4PYkySDh15oR7bOA@mail.gmail.com>
References: <tencent_267C505771F9162A6E330836@qq.com>
	<CAKoxK+64bLMR8nuMyrRwjvQD90o4e=LVNgEMysy16btuwmhXKg@mail.gmail.com>
	<tencent_3398A66F571334E95E5B4093@qq.com>
	<tencent_3DC4B18C6E40FB7B57E655F2@qq.com>
	<CAKoxK+4iRo1V+EJGKSgCjqutwjdLDsFghi4PYkySDh15oR7bOA@mail.gmail.com>

Hi Luca,


Yes, that's the answer,It really works!
Thanks again Luca, you actually saved my day!


James.
------------------ Original ------------------
From:  "Luca Ferrari"<fluca1978@gmail.com>;
Date:  Wed, Jul 17, 2019 06:49 PM
To:  "James(王旭)"<wangxu@gu360.com>; 
Cc:  "pgsql-general"<pgsql-general@lists.postgresql.org>; 
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?

 

On Wed, Jul 17, 2019 at 11:41 AM James(王旭) <wangxu@gu360.com> wrote:
> From these results I can tell the route to a table is not even related with the mod function, right?
> So It's hard for me to do any kind of guesses...

Because it is the wrong function.
According to \d+ on a child table and partbounds.c the function called
is satisfied_hash_partition:

testdb=# select satisfies_hash_partition('153221'::oid, 3, 0, 6521);
 satisfies_hash_partition
--------------------------
 t
(1 row)

testdb=# select satisfies_hash_partition('153221'::oid, 3, 1, 6521);
 satisfies_hash_partition
--------------------------
 f
(1 row)

The first argument is the table id (partitioned one, the root), the
second is the reminder, third is the partition table, last is your
value.
Therefore I suspect you have to iterate on your partition numbers from
0 to x to see if a value fits in that partition, and then extract the
table name from that.

Hope its clear.

Luca

view thread (6+ messages)

Message-ID: <tencent_10CD0FFC540E29992BA299BA@qq.com>
Permalink:  ../tencent_10CD0FFC540E29992BA299BA@qq.com/
Also on:    postgresql.org/message-id/tencent_10CD0FFC540E29992BA299BA@qq.com

 · 

reply

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, fluca1978@gmail.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_10CD0FFC540E29992BA299BA@qq.com>
  References: <tencent_267C505771F9162A6E330836@qq.com> <CAKoxK+64bLMR8nuMyrRwjvQD90o4e=LVNgEMysy16btuwmhXKg@mail.gmail.com> <tencent_3398A66F571334E95E5B4093@qq.com> <tencent_3DC4B18C6E40FB7B57E655F2@qq.com> <CAKoxK+4iRo1V+EJGKSgCjqutwjdLDsFghi4PYkySDh15oR7bOA@mail.gmail.com> <tencent_10CD0FFC540E29992BA299BA@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