Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1astP3-0003pN-9b for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Apr 2016 14:46:53 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1astP1-00077v-Kl for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Apr 2016 14:46:51 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1astP0-00077p-Q6 for pgsql-hackers@postgresql.org; Wed, 20 Apr 2016 14:46:51 +0000 Received: from newmail.postgrespro.ru ([93.174.131.138] helo=mail.postgrespro.ru) by makus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1astOx-0007GN-Jv for pgsql-hackers@postgresql.org; Wed, 20 Apr 2016 14:46:49 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 462C221C7E53; Wed, 20 Apr 2016 17:46:45 +0300 (MSK) Received: from mail.postgrespro.ru ([127.0.0.1]) by localhost (mail.postgrespro.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kfpGAuvu7lGI; Wed, 20 Apr 2016 17:46:43 +0300 (MSK) Received: from [192.168.27.107] (unknown [192.168.27.1]) by mail.postgrespro.ru (Postfix) with ESMTPSA id CE60C21C7E33; Wed, 20 Apr 2016 17:46:43 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1461163603; bh=HRuMsAmbn6wTGTxJUKgGUVhNZrbmgz/lNkL8MwxAzdQ=; h=Subject:To:References:Cc:From:Date:In-Reply-To; b=cmqx/fc+j5p+qSUao7yoI3EcRw1QlKPu4T6s7asTr+xdVAtahOA03fD2tlb5i0jbg HDdDmh/eLg6QToRAaVseRphUlrHT0y/+tbwrqKf931JL2tRSsU0BaT/0tsOGza4rcP iLE+Fr5RxFJvMHGX0oqzodM4DwPMfLWtN/PbMAAA= Subject: Re: Declarative partitioning To: Amit Langote , Amit Langote , Alexander Korotkov References: <55D3093C.5010800@lab.ntt.co.jp> <56C55973.80309@lab.ntt.co.jp> <56CD6598.4090302@lab.ntt.co.jp> <56DE2D4B.1040001@lab.ntt.co.jp> <56DF74F0.7060404@lab.ntt.co.jp> <56F0AC96.2010303@lab.ntt.co.jp> <57106F9E.3000309@lab.ntt.co.jp> <57163954.2020701@postgrespro.ru> <571759D8.7030205@lab.ntt.co.jp> Cc: Ashutosh Bapat , Robert Haas , Corey Huinker , Pg Hackers From: Ildar Musin Message-ID: <57179653.30905@postgrespro.ru> Date: Wed, 20 Apr 2016 17:46:43 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <571759D8.7030205@lab.ntt.co.jp> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -3.0 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Hi Amit, On 20.04.2016 13:28, Amit Langote wrote: > On 2016/04/19 23:52, Amit Langote wrote: >> On Tue, Apr 19, 2016 at 11:26 PM, Alexander Korotkov >>> Another question is that it might be NOT what users expect from that. From >>> the syntax side it very looks like defining something boxes regions for two >>> keys which could be replacement for subpartitioning. But it isn't so. >> Need to check why query with qual b < 100 behaves the way it does. >> Something's going wrong there with the constraints (partition >> predicates) that are being generated internally (as mentioned before, >> still driven by constraint exclusion using the constraints generated >> on-the-fly). >> >> As for the composite range partition bounds in Ildar's example, it's >> as if the second value in the key never determines the fate of a row >> going into some partition, therefore no constraints should have been >> generated for column b of the key. I'm afraid that's not the case as >> per the latest patch. Will fix. > The strange behavior that Ildar reported should have been fixed with the > attached updated set of patches (v2): > > create table test(a int, b int) partition by range (a, b); > create table test_1 partition of test for values start (0, 0) end (100, 100); > create table test_2 partition of test for values start (100, 100) end > (200, 200); > create table test_3 partition of test for values start (200, 200) end > (300, 300); > CREATE TABLE > CREATE TABLE > CREATE TABLE > CREATE TABLE > > insert into test(a, b) values (150, 50); > INSERT 0 1 > > select * from test where b < 100; > a | b > -----+---- > 150 | 50 > (1 row) > > explain (costs off) select * from test where b < 100; > QUERY PLAN > --------------------------- > Append > -> Seq Scan on test > Filter: (b < 100) > -> Seq Scan on test_1 > Filter: (b < 100) > -> Seq Scan on test_2 > Filter: (b < 100) > -> Seq Scan on test_3 > Filter: (b < 100) > (9 rows) > > > Multi-column range partitioning seems a bit tricky as far as generating > constraints on individual columns using a partition's lower and upper > bounds (both composite values) is concerned. I mentally pictured > something like the following example scenario: > > create table test(a int, b int, c int) > partition by range (a, b, c); > create table test_1 partition of test > for values start (0, 0, 0) end (0, 2, 0); > create table test_2 partition of test > for values start (0, 2, 0) end (0, 3, 0); > create table test_3 partition of test > for values start (0, 3, 0) end (0, 4, 0); > create table test_4 partition of test > for values start (0, 4, 0) end (1, 0, 0); > create table test_5 partition of test > for values start (1, 0, 0) end (1, 2, 0); > create table test_6 partition of test > for values start (1, 2, 0) end (1, 3, 0); > create table test_7 partition of test > for values start (1, 3, 0) end (1, 4, 0); > create table test_8 partition of test > for values start (1, 4, 0) end (2, 0, 0); > > Useful to think of the above as sequence of ranges [000, 020), [020, 030), > [030, 040), [040, 100), [100, 120), [120, 130), [130, 140), [140, 200) for > purposes of finding the partition for a row. > > Then constraints generated internally for each partition: > > test_1: a = 0 AND b >= 0 AND b <= 2 > test_2: a = 0 AND b >= 2 AND b <= 3 > test_3: a = 0 AND b >= 3 AND b <= 4 > test_4: a >= 0 AND a <= 1 > test_5: a = 1 AND b >= 0 AND b <= 2 > test_6: a = 1 AND b >= 2 AND b <= 3 > test_7: a = 1 AND b >= 3 AND b <= 4 > test_8: a >= 1 AND a <= 2 > > I will try further to poke holes in my thinking about this. Please feel > free to point out if you find any. > > Thanks, > Amit Thanks for clarification! I tried the updated patch, now it works correctly. I encountered another problem that concerns expressions as partitioning key. Probably there is still some work in progress. But if it will help here is my case: create table inh(a int, b int) partition by range ((a+b)); create table inh_1 partition of inh for values start (0) end (10); create table inh_2 partition of inh for values start (10) end (20); Then if we run any SELECT query it crashes postgres: select * from inh; Crash occurs in get_check_expr_from_partbound(). It seems that function is not yet expecting an expression key and designed to handle only simple attributes keys. Backtrace: #0 strlen () at ../sysdeps/x86_64/strlen.S:106 #1 0x00000000004add8a in hashname (fcinfo=0x7ffdbdb9c760) at hashfunc.c:145 #2 0x000000000099cc08 in DirectFunctionCall1Coll (func=0x4add66 , collation=0, arg1=0) at fmgr.c:1027 #3 0x00000000009724dd in CatalogCacheComputeHashValue (cache=0x26590b0, nkeys=2, cur_skey=0x7ffdbdb9cbf0) at catcache.c:207 #4 0x0000000000974979 in SearchCatCache (cache=0x26590b0, v1=32807, v2=0, v3=0, v4=0) at catcache.c:1151 #5 0x0000000000988e35 in SearchSysCache (cacheId=6, key1=32807, key2=0, key3=0, key4=0) at syscache.c:1006 #6 0x0000000000988fe3 in SearchSysCacheAttName (relid=32807, attname=0x0) at syscache.c:1106 #7 0x000000000098a744 in get_attnum (relid=32807, attname=0x0) at lsyscache.c:825 #8 0x000000000056afd2 in get_check_expr_from_partbound (rel=0x7f868601ca20, parent=0x7f868601b770, bound=0x26e6ac8) at partition.c:1427 #9 0x000000000056bc9e in generate_partition_check_expr (rel=0x7f868601ca20) at partition.c:1788 #10 0x000000000056bb5f in RelationGetPartitionCheckExpr (rel=0x7f868601ca20) at partition.c:1746 #11 0x0000000000782b5f in get_relation_constraints (root=0x268f1b8, relationObjectId=32807, rel=0x26e5cd8, include_notnull=1 '\001') at plancat.c:1209 #12 0x0000000000782d74 in relation_excluded_by_constraints (root=0x268f1b8, rel=0x26e5cd8, rte=0x268ebf0) at plancat.c:1302 #13 0x000000000072a18d in set_append_rel_size (root=0x268f1b8, rel=0x26e5690, rti=1, rte=0x268ea80) at allpaths.c:947 ... -- Ildar Musin i.musin@postgrespro.ru -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers