mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-04 00:02:52 -05:00 
			
		
		
		
	Attempt to fix endianess issues in new hash partition test.
The tests added as part of 9fdb675fc5 yield differing results depending on endianess, causing buildfarm failures. As the differences are expected, split the hash partitioning tests into a different file and maintain alternative output. The separate file is so the amount of duplicated output is reduced. David produced the alternative output without a machine to test on, so it's possible this'll require a buildfarm cycle or two to get right. Author: David Rowley Discussion: https://postgr.es/m/CAKJS1f-6f4c2Qhuipe-GY7BKmFd0FMBobRnLS7hVCoAmTszsBg@mail.gmail.com
This commit is contained in:
		
							parent
							
								
									8c3debbbf6
								
							
						
					
					
						commit
						40e42e1024
					
				@ -1331,188 +1331,3 @@ explain (costs off) select * from rparted_by_int2 where a > 100000000000000;
 | 
			
		||||
(3 rows)
 | 
			
		||||
 | 
			
		||||
drop table lp, coll_pruning, rlp, mc3p, mc2p, boolpart, rp, coll_pruning_multi, like_op_noprune, lparted_by_int2, rparted_by_int2;
 | 
			
		||||
-- hash partitioning
 | 
			
		||||
create table hp (a int, b text) partition by hash (a, b);
 | 
			
		||||
create table hp0 partition of hp for values with (modulus 4, remainder 0);
 | 
			
		||||
create table hp3 partition of hp for values with (modulus 4, remainder 3);
 | 
			
		||||
create table hp1 partition of hp for values with (modulus 4, remainder 1);
 | 
			
		||||
create table hp2 partition of hp for values with (modulus 4, remainder 2);
 | 
			
		||||
insert into hp values (null, null);
 | 
			
		||||
insert into hp values (1, null);
 | 
			
		||||
insert into hp values (1, 'xxx');
 | 
			
		||||
insert into hp values (null, 'xxx');
 | 
			
		||||
insert into hp values (10, 'xxx');
 | 
			
		||||
insert into hp values (10, 'yyy');
 | 
			
		||||
select tableoid::regclass, * from hp order by 1;
 | 
			
		||||
 tableoid | a  |  b  
 | 
			
		||||
----------+----+-----
 | 
			
		||||
 hp0      |    | 
 | 
			
		||||
 hp0      |  1 | 
 | 
			
		||||
 hp0      |  1 | xxx
 | 
			
		||||
 hp3      | 10 | yyy
 | 
			
		||||
 hp1      |    | xxx
 | 
			
		||||
 hp2      | 10 | xxx
 | 
			
		||||
(6 rows)
 | 
			
		||||
 | 
			
		||||
-- partial keys won't prune, nor would non-equality conditions
 | 
			
		||||
explain (costs off) select * from hp where a = 1;
 | 
			
		||||
       QUERY PLAN        
 | 
			
		||||
-------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: (a = 1)
 | 
			
		||||
   ->  Seq Scan on hp1
 | 
			
		||||
         Filter: (a = 1)
 | 
			
		||||
   ->  Seq Scan on hp2
 | 
			
		||||
         Filter: (a = 1)
 | 
			
		||||
   ->  Seq Scan on hp3
 | 
			
		||||
         Filter: (a = 1)
 | 
			
		||||
(9 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where b = 'xxx';
 | 
			
		||||
            QUERY PLAN             
 | 
			
		||||
-----------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: (b = 'xxx'::text)
 | 
			
		||||
   ->  Seq Scan on hp1
 | 
			
		||||
         Filter: (b = 'xxx'::text)
 | 
			
		||||
   ->  Seq Scan on hp2
 | 
			
		||||
         Filter: (b = 'xxx'::text)
 | 
			
		||||
   ->  Seq Scan on hp3
 | 
			
		||||
         Filter: (b = 'xxx'::text)
 | 
			
		||||
(9 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where a is null;
 | 
			
		||||
         QUERY PLAN          
 | 
			
		||||
-----------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: (a IS NULL)
 | 
			
		||||
   ->  Seq Scan on hp1
 | 
			
		||||
         Filter: (a IS NULL)
 | 
			
		||||
   ->  Seq Scan on hp2
 | 
			
		||||
         Filter: (a IS NULL)
 | 
			
		||||
   ->  Seq Scan on hp3
 | 
			
		||||
         Filter: (a IS NULL)
 | 
			
		||||
(9 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where b is null;
 | 
			
		||||
         QUERY PLAN          
 | 
			
		||||
-----------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: (b IS NULL)
 | 
			
		||||
   ->  Seq Scan on hp1
 | 
			
		||||
         Filter: (b IS NULL)
 | 
			
		||||
   ->  Seq Scan on hp2
 | 
			
		||||
         Filter: (b IS NULL)
 | 
			
		||||
   ->  Seq Scan on hp3
 | 
			
		||||
         Filter: (b IS NULL)
 | 
			
		||||
(9 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where a < 1 and b = 'xxx';
 | 
			
		||||
                   QUERY PLAN                    
 | 
			
		||||
-------------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: ((a < 1) AND (b = 'xxx'::text))
 | 
			
		||||
   ->  Seq Scan on hp1
 | 
			
		||||
         Filter: ((a < 1) AND (b = 'xxx'::text))
 | 
			
		||||
   ->  Seq Scan on hp2
 | 
			
		||||
         Filter: ((a < 1) AND (b = 'xxx'::text))
 | 
			
		||||
   ->  Seq Scan on hp3
 | 
			
		||||
         Filter: ((a < 1) AND (b = 'xxx'::text))
 | 
			
		||||
(9 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where a <> 1 and b = 'yyy';
 | 
			
		||||
                    QUERY PLAN                    
 | 
			
		||||
--------------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: ((a <> 1) AND (b = 'yyy'::text))
 | 
			
		||||
   ->  Seq Scan on hp1
 | 
			
		||||
         Filter: ((a <> 1) AND (b = 'yyy'::text))
 | 
			
		||||
   ->  Seq Scan on hp2
 | 
			
		||||
         Filter: ((a <> 1) AND (b = 'yyy'::text))
 | 
			
		||||
   ->  Seq Scan on hp3
 | 
			
		||||
         Filter: ((a <> 1) AND (b = 'yyy'::text))
 | 
			
		||||
(9 rows)
 | 
			
		||||
 | 
			
		||||
-- pruning should work if non-null values are provided for all the keys
 | 
			
		||||
explain (costs off) select * from hp where a is null and b is null;
 | 
			
		||||
                  QUERY PLAN                   
 | 
			
		||||
-----------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: ((a IS NULL) AND (b IS NULL))
 | 
			
		||||
(3 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where a = 1 and b is null;
 | 
			
		||||
                QUERY PLAN                 
 | 
			
		||||
-------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: ((b IS NULL) AND (a = 1))
 | 
			
		||||
(3 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where a = 1 and b = 'xxx';
 | 
			
		||||
                   QUERY PLAN                    
 | 
			
		||||
-------------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: ((a = 1) AND (b = 'xxx'::text))
 | 
			
		||||
(3 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where a is null and b = 'xxx';
 | 
			
		||||
                     QUERY PLAN                      
 | 
			
		||||
-----------------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp1
 | 
			
		||||
         Filter: ((a IS NULL) AND (b = 'xxx'::text))
 | 
			
		||||
(3 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where a = 10 and b = 'xxx';
 | 
			
		||||
                    QUERY PLAN                    
 | 
			
		||||
--------------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp2
 | 
			
		||||
         Filter: ((a = 10) AND (b = 'xxx'::text))
 | 
			
		||||
(3 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where a = 10 and b = 'yyy';
 | 
			
		||||
                    QUERY PLAN                    
 | 
			
		||||
--------------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp3
 | 
			
		||||
         Filter: ((a = 10) AND (b = 'yyy'::text))
 | 
			
		||||
(3 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where (a = 10 and b = 'yyy') or (a = 10 and b = 'xxx') or (a is null and b is null);
 | 
			
		||||
                                                       QUERY PLAN                                                        
 | 
			
		||||
-------------------------------------------------------------------------------------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: (((a = 10) AND (b = 'yyy'::text)) OR ((a = 10) AND (b = 'xxx'::text)) OR ((a IS NULL) AND (b IS NULL)))
 | 
			
		||||
   ->  Seq Scan on hp2
 | 
			
		||||
         Filter: (((a = 10) AND (b = 'yyy'::text)) OR ((a = 10) AND (b = 'xxx'::text)) OR ((a IS NULL) AND (b IS NULL)))
 | 
			
		||||
   ->  Seq Scan on hp3
 | 
			
		||||
         Filter: (((a = 10) AND (b = 'yyy'::text)) OR ((a = 10) AND (b = 'xxx'::text)) OR ((a IS NULL) AND (b IS NULL)))
 | 
			
		||||
(7 rows)
 | 
			
		||||
 | 
			
		||||
-- hash partitiong pruning doesn't occur with <> operator clauses
 | 
			
		||||
explain (costs off) select * from hp where a <> 1 and b <> 'xxx';
 | 
			
		||||
                    QUERY PLAN                     
 | 
			
		||||
---------------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: ((a <> 1) AND (b <> 'xxx'::text))
 | 
			
		||||
   ->  Seq Scan on hp1
 | 
			
		||||
         Filter: ((a <> 1) AND (b <> 'xxx'::text))
 | 
			
		||||
   ->  Seq Scan on hp2
 | 
			
		||||
         Filter: ((a <> 1) AND (b <> 'xxx'::text))
 | 
			
		||||
   ->  Seq Scan on hp3
 | 
			
		||||
         Filter: ((a <> 1) AND (b <> 'xxx'::text))
 | 
			
		||||
(9 rows)
 | 
			
		||||
 | 
			
		||||
drop table hp;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										189
									
								
								src/test/regress/expected/partition_prune_hash.out
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										189
									
								
								src/test/regress/expected/partition_prune_hash.out
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,189 @@
 | 
			
		||||
--
 | 
			
		||||
-- Test Partition pruning for HASH partitioning
 | 
			
		||||
-- We keep this as a seperate test as hash functions return
 | 
			
		||||
-- values will vary based on CPU architecture.
 | 
			
		||||
--
 | 
			
		||||
create table hp (a int, b text) partition by hash (a, b);
 | 
			
		||||
create table hp0 partition of hp for values with (modulus 4, remainder 0);
 | 
			
		||||
create table hp3 partition of hp for values with (modulus 4, remainder 3);
 | 
			
		||||
create table hp1 partition of hp for values with (modulus 4, remainder 1);
 | 
			
		||||
create table hp2 partition of hp for values with (modulus 4, remainder 2);
 | 
			
		||||
insert into hp values (null, null);
 | 
			
		||||
insert into hp values (1, null);
 | 
			
		||||
insert into hp values (1, 'xxx');
 | 
			
		||||
insert into hp values (null, 'xxx');
 | 
			
		||||
insert into hp values (10, 'xxx');
 | 
			
		||||
insert into hp values (10, 'yyy');
 | 
			
		||||
select tableoid::regclass, * from hp order by 1;
 | 
			
		||||
 tableoid | a  |  b  
 | 
			
		||||
----------+----+-----
 | 
			
		||||
 hp0      |    | 
 | 
			
		||||
 hp0      |  1 | 
 | 
			
		||||
 hp0      |  1 | xxx
 | 
			
		||||
 hp3      | 10 | yyy
 | 
			
		||||
 hp1      |    | xxx
 | 
			
		||||
 hp2      | 10 | xxx
 | 
			
		||||
(6 rows)
 | 
			
		||||
 | 
			
		||||
-- partial keys won't prune, nor would non-equality conditions
 | 
			
		||||
explain (costs off) select * from hp where a = 1;
 | 
			
		||||
       QUERY PLAN        
 | 
			
		||||
-------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: (a = 1)
 | 
			
		||||
   ->  Seq Scan on hp1
 | 
			
		||||
         Filter: (a = 1)
 | 
			
		||||
   ->  Seq Scan on hp2
 | 
			
		||||
         Filter: (a = 1)
 | 
			
		||||
   ->  Seq Scan on hp3
 | 
			
		||||
         Filter: (a = 1)
 | 
			
		||||
(9 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where b = 'xxx';
 | 
			
		||||
            QUERY PLAN             
 | 
			
		||||
-----------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: (b = 'xxx'::text)
 | 
			
		||||
   ->  Seq Scan on hp1
 | 
			
		||||
         Filter: (b = 'xxx'::text)
 | 
			
		||||
   ->  Seq Scan on hp2
 | 
			
		||||
         Filter: (b = 'xxx'::text)
 | 
			
		||||
   ->  Seq Scan on hp3
 | 
			
		||||
         Filter: (b = 'xxx'::text)
 | 
			
		||||
(9 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where a is null;
 | 
			
		||||
         QUERY PLAN          
 | 
			
		||||
-----------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: (a IS NULL)
 | 
			
		||||
   ->  Seq Scan on hp1
 | 
			
		||||
         Filter: (a IS NULL)
 | 
			
		||||
   ->  Seq Scan on hp2
 | 
			
		||||
         Filter: (a IS NULL)
 | 
			
		||||
   ->  Seq Scan on hp3
 | 
			
		||||
         Filter: (a IS NULL)
 | 
			
		||||
(9 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where b is null;
 | 
			
		||||
         QUERY PLAN          
 | 
			
		||||
-----------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: (b IS NULL)
 | 
			
		||||
   ->  Seq Scan on hp1
 | 
			
		||||
         Filter: (b IS NULL)
 | 
			
		||||
   ->  Seq Scan on hp2
 | 
			
		||||
         Filter: (b IS NULL)
 | 
			
		||||
   ->  Seq Scan on hp3
 | 
			
		||||
         Filter: (b IS NULL)
 | 
			
		||||
(9 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where a < 1 and b = 'xxx';
 | 
			
		||||
                   QUERY PLAN                    
 | 
			
		||||
-------------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: ((a < 1) AND (b = 'xxx'::text))
 | 
			
		||||
   ->  Seq Scan on hp1
 | 
			
		||||
         Filter: ((a < 1) AND (b = 'xxx'::text))
 | 
			
		||||
   ->  Seq Scan on hp2
 | 
			
		||||
         Filter: ((a < 1) AND (b = 'xxx'::text))
 | 
			
		||||
   ->  Seq Scan on hp3
 | 
			
		||||
         Filter: ((a < 1) AND (b = 'xxx'::text))
 | 
			
		||||
(9 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where a <> 1 and b = 'yyy';
 | 
			
		||||
                    QUERY PLAN                    
 | 
			
		||||
--------------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: ((a <> 1) AND (b = 'yyy'::text))
 | 
			
		||||
   ->  Seq Scan on hp1
 | 
			
		||||
         Filter: ((a <> 1) AND (b = 'yyy'::text))
 | 
			
		||||
   ->  Seq Scan on hp2
 | 
			
		||||
         Filter: ((a <> 1) AND (b = 'yyy'::text))
 | 
			
		||||
   ->  Seq Scan on hp3
 | 
			
		||||
         Filter: ((a <> 1) AND (b = 'yyy'::text))
 | 
			
		||||
(9 rows)
 | 
			
		||||
 | 
			
		||||
-- pruning should work if non-null values are provided for all the keys
 | 
			
		||||
explain (costs off) select * from hp where a is null and b is null;
 | 
			
		||||
                  QUERY PLAN                   
 | 
			
		||||
-----------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: ((a IS NULL) AND (b IS NULL))
 | 
			
		||||
(3 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where a = 1 and b is null;
 | 
			
		||||
                QUERY PLAN                 
 | 
			
		||||
-------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: ((b IS NULL) AND (a = 1))
 | 
			
		||||
(3 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where a = 1 and b = 'xxx';
 | 
			
		||||
                   QUERY PLAN                    
 | 
			
		||||
-------------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: ((a = 1) AND (b = 'xxx'::text))
 | 
			
		||||
(3 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where a is null and b = 'xxx';
 | 
			
		||||
                     QUERY PLAN                      
 | 
			
		||||
-----------------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp1
 | 
			
		||||
         Filter: ((a IS NULL) AND (b = 'xxx'::text))
 | 
			
		||||
(3 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where a = 10 and b = 'xxx';
 | 
			
		||||
                    QUERY PLAN                    
 | 
			
		||||
--------------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp2
 | 
			
		||||
         Filter: ((a = 10) AND (b = 'xxx'::text))
 | 
			
		||||
(3 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where a = 10 and b = 'yyy';
 | 
			
		||||
                    QUERY PLAN                    
 | 
			
		||||
--------------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp3
 | 
			
		||||
         Filter: ((a = 10) AND (b = 'yyy'::text))
 | 
			
		||||
(3 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where (a = 10 and b = 'yyy') or (a = 10 and b = 'xxx') or (a is null and b is null);
 | 
			
		||||
                                                       QUERY PLAN                                                        
 | 
			
		||||
-------------------------------------------------------------------------------------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: (((a = 10) AND (b = 'yyy'::text)) OR ((a = 10) AND (b = 'xxx'::text)) OR ((a IS NULL) AND (b IS NULL)))
 | 
			
		||||
   ->  Seq Scan on hp2
 | 
			
		||||
         Filter: (((a = 10) AND (b = 'yyy'::text)) OR ((a = 10) AND (b = 'xxx'::text)) OR ((a IS NULL) AND (b IS NULL)))
 | 
			
		||||
   ->  Seq Scan on hp3
 | 
			
		||||
         Filter: (((a = 10) AND (b = 'yyy'::text)) OR ((a = 10) AND (b = 'xxx'::text)) OR ((a IS NULL) AND (b IS NULL)))
 | 
			
		||||
(7 rows)
 | 
			
		||||
 | 
			
		||||
-- hash partitiong pruning doesn't occur with <> operator clauses
 | 
			
		||||
explain (costs off) select * from hp where a <> 1 and b <> 'xxx';
 | 
			
		||||
                    QUERY PLAN                     
 | 
			
		||||
---------------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: ((a <> 1) AND (b <> 'xxx'::text))
 | 
			
		||||
   ->  Seq Scan on hp1
 | 
			
		||||
         Filter: ((a <> 1) AND (b <> 'xxx'::text))
 | 
			
		||||
   ->  Seq Scan on hp2
 | 
			
		||||
         Filter: ((a <> 1) AND (b <> 'xxx'::text))
 | 
			
		||||
   ->  Seq Scan on hp3
 | 
			
		||||
         Filter: ((a <> 1) AND (b <> 'xxx'::text))
 | 
			
		||||
(9 rows)
 | 
			
		||||
 | 
			
		||||
drop table hp;
 | 
			
		||||
							
								
								
									
										187
									
								
								src/test/regress/expected/partition_prune_hash_1.out
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										187
									
								
								src/test/regress/expected/partition_prune_hash_1.out
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,187 @@
 | 
			
		||||
--
 | 
			
		||||
-- Test Partition pruning for HASH partitioning
 | 
			
		||||
-- We keep this as a seperate test as hash functions return
 | 
			
		||||
-- values will vary based on CPU architecture.
 | 
			
		||||
--
 | 
			
		||||
create table hp (a int, b text) partition by hash (a, b);
 | 
			
		||||
create table hp0 partition of hp for values with (modulus 4, remainder 0);
 | 
			
		||||
create table hp3 partition of hp for values with (modulus 4, remainder 3);
 | 
			
		||||
create table hp1 partition of hp for values with (modulus 4, remainder 1);
 | 
			
		||||
create table hp2 partition of hp for values with (modulus 4, remainder 2);
 | 
			
		||||
insert into hp values (null, null);
 | 
			
		||||
insert into hp values (1, null);
 | 
			
		||||
insert into hp values (1, 'xxx');
 | 
			
		||||
insert into hp values (null, 'xxx');
 | 
			
		||||
insert into hp values (10, 'xxx');
 | 
			
		||||
insert into hp values (10, 'yyy');
 | 
			
		||||
select tableoid::regclass, * from hp order by 1;
 | 
			
		||||
 tableoid | a  |  b  
 | 
			
		||||
----------+----+-----
 | 
			
		||||
 hp0      |    | 
 | 
			
		||||
 hp0      |  1 | 
 | 
			
		||||
 hp0      | 10 | xxx
 | 
			
		||||
 hp3      |    | xxx
 | 
			
		||||
 hp3      | 10 | yyy
 | 
			
		||||
 hp2      |  1 | xxx
 | 
			
		||||
(6 rows)
 | 
			
		||||
 | 
			
		||||
-- partial keys won't prune, nor would non-equality conditions
 | 
			
		||||
explain (costs off) select * from hp where a = 1;
 | 
			
		||||
       QUERY PLAN        
 | 
			
		||||
-------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: (a = 1)
 | 
			
		||||
   ->  Seq Scan on hp1
 | 
			
		||||
         Filter: (a = 1)
 | 
			
		||||
   ->  Seq Scan on hp2
 | 
			
		||||
         Filter: (a = 1)
 | 
			
		||||
   ->  Seq Scan on hp3
 | 
			
		||||
         Filter: (a = 1)
 | 
			
		||||
(9 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where b = 'xxx';
 | 
			
		||||
            QUERY PLAN             
 | 
			
		||||
-----------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: (b = 'xxx'::text)
 | 
			
		||||
   ->  Seq Scan on hp1
 | 
			
		||||
         Filter: (b = 'xxx'::text)
 | 
			
		||||
   ->  Seq Scan on hp2
 | 
			
		||||
         Filter: (b = 'xxx'::text)
 | 
			
		||||
   ->  Seq Scan on hp3
 | 
			
		||||
         Filter: (b = 'xxx'::text)
 | 
			
		||||
(9 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where a is null;
 | 
			
		||||
         QUERY PLAN          
 | 
			
		||||
-----------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: (a IS NULL)
 | 
			
		||||
   ->  Seq Scan on hp1
 | 
			
		||||
         Filter: (a IS NULL)
 | 
			
		||||
   ->  Seq Scan on hp2
 | 
			
		||||
         Filter: (a IS NULL)
 | 
			
		||||
   ->  Seq Scan on hp3
 | 
			
		||||
         Filter: (a IS NULL)
 | 
			
		||||
(9 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where b is null;
 | 
			
		||||
         QUERY PLAN          
 | 
			
		||||
-----------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: (b IS NULL)
 | 
			
		||||
   ->  Seq Scan on hp1
 | 
			
		||||
         Filter: (b IS NULL)
 | 
			
		||||
   ->  Seq Scan on hp2
 | 
			
		||||
         Filter: (b IS NULL)
 | 
			
		||||
   ->  Seq Scan on hp3
 | 
			
		||||
         Filter: (b IS NULL)
 | 
			
		||||
(9 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where a < 1 and b = 'xxx';
 | 
			
		||||
                   QUERY PLAN                    
 | 
			
		||||
-------------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: ((a < 1) AND (b = 'xxx'::text))
 | 
			
		||||
   ->  Seq Scan on hp1
 | 
			
		||||
         Filter: ((a < 1) AND (b = 'xxx'::text))
 | 
			
		||||
   ->  Seq Scan on hp2
 | 
			
		||||
         Filter: ((a < 1) AND (b = 'xxx'::text))
 | 
			
		||||
   ->  Seq Scan on hp3
 | 
			
		||||
         Filter: ((a < 1) AND (b = 'xxx'::text))
 | 
			
		||||
(9 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where a <> 1 and b = 'yyy';
 | 
			
		||||
                    QUERY PLAN                    
 | 
			
		||||
--------------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: ((a <> 1) AND (b = 'yyy'::text))
 | 
			
		||||
   ->  Seq Scan on hp1
 | 
			
		||||
         Filter: ((a <> 1) AND (b = 'yyy'::text))
 | 
			
		||||
   ->  Seq Scan on hp2
 | 
			
		||||
         Filter: ((a <> 1) AND (b = 'yyy'::text))
 | 
			
		||||
   ->  Seq Scan on hp3
 | 
			
		||||
         Filter: ((a <> 1) AND (b = 'yyy'::text))
 | 
			
		||||
(9 rows)
 | 
			
		||||
 | 
			
		||||
-- pruning should work if non-null values are provided for all the keys
 | 
			
		||||
explain (costs off) select * from hp where a is null and b is null;
 | 
			
		||||
                  QUERY PLAN                   
 | 
			
		||||
-----------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: ((a IS NULL) AND (b IS NULL))
 | 
			
		||||
(3 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where a = 1 and b is null;
 | 
			
		||||
                QUERY PLAN                 
 | 
			
		||||
-------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: ((b IS NULL) AND (a = 1))
 | 
			
		||||
(3 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where a = 1 and b = 'xxx';
 | 
			
		||||
                   QUERY PLAN                    
 | 
			
		||||
-------------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp2
 | 
			
		||||
         Filter: ((a = 1) AND (b = 'xxx'::text))
 | 
			
		||||
(3 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where a is null and b = 'xxx';
 | 
			
		||||
                     QUERY PLAN                      
 | 
			
		||||
-----------------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp3
 | 
			
		||||
         Filter: ((a IS NULL) AND (b = 'xxx'::text))
 | 
			
		||||
(3 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where a = 10 and b = 'xxx';
 | 
			
		||||
                    QUERY PLAN                    
 | 
			
		||||
--------------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: ((a = 10) AND (b = 'xxx'::text))
 | 
			
		||||
(3 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where a = 10 and b = 'yyy';
 | 
			
		||||
                    QUERY PLAN                    
 | 
			
		||||
--------------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp3
 | 
			
		||||
         Filter: ((a = 10) AND (b = 'yyy'::text))
 | 
			
		||||
(3 rows)
 | 
			
		||||
 | 
			
		||||
explain (costs off) select * from hp where (a = 10 and b = 'yyy') or (a = 10 and b = 'xxx') or (a is null and b is null);
 | 
			
		||||
                                                       QUERY PLAN                                                        
 | 
			
		||||
-------------------------------------------------------------------------------------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: (((a = 10) AND (b = 'yyy'::text)) OR ((a = 10) AND (b = 'xxx'::text)) OR ((a IS NULL) AND (b IS NULL)))
 | 
			
		||||
   ->  Seq Scan on hp3
 | 
			
		||||
         Filter: (((a = 10) AND (b = 'yyy'::text)) OR ((a = 10) AND (b = 'xxx'::text)) OR ((a IS NULL) AND (b IS NULL)))
 | 
			
		||||
(5 rows)
 | 
			
		||||
 | 
			
		||||
-- hash partitiong pruning doesn't occur with <> operator clauses
 | 
			
		||||
explain (costs off) select * from hp where a <> 1 and b <> 'xxx';
 | 
			
		||||
                    QUERY PLAN                     
 | 
			
		||||
---------------------------------------------------
 | 
			
		||||
 Append
 | 
			
		||||
   ->  Seq Scan on hp0
 | 
			
		||||
         Filter: ((a <> 1) AND (b <> 'xxx'::text))
 | 
			
		||||
   ->  Seq Scan on hp1
 | 
			
		||||
         Filter: ((a <> 1) AND (b <> 'xxx'::text))
 | 
			
		||||
   ->  Seq Scan on hp2
 | 
			
		||||
         Filter: ((a <> 1) AND (b <> 'xxx'::text))
 | 
			
		||||
   ->  Seq Scan on hp3
 | 
			
		||||
         Filter: ((a <> 1) AND (b <> 'xxx'::text))
 | 
			
		||||
(9 rows)
 | 
			
		||||
 | 
			
		||||
drop table hp;
 | 
			
		||||
@ -116,7 +116,7 @@ test: plancache limit plpgsql copy2 temp domain rangefuncs prepare without_oid c
 | 
			
		||||
# ----------
 | 
			
		||||
# Another group of parallel tests
 | 
			
		||||
# ----------
 | 
			
		||||
test: identity partition_join partition_prune reloptions hash_part indexing partition_aggregate fast_default
 | 
			
		||||
test: identity partition_join partition_prune partition_prune_hash reloptions hash_part indexing partition_aggregate fast_default
 | 
			
		||||
 | 
			
		||||
# event triggers cannot run concurrently with any test that runs DDL
 | 
			
		||||
test: event_trigger
 | 
			
		||||
 | 
			
		||||
@ -184,6 +184,7 @@ test: xml
 | 
			
		||||
test: identity
 | 
			
		||||
test: partition_join
 | 
			
		||||
test: partition_prune
 | 
			
		||||
test: partition_prune_hash
 | 
			
		||||
test: reloptions
 | 
			
		||||
test: hash_part
 | 
			
		||||
test: indexing
 | 
			
		||||
 | 
			
		||||
@ -237,40 +237,3 @@ create table rparted_by_int2_maxvalue partition of rparted_by_int2 for values fr
 | 
			
		||||
explain (costs off) select * from rparted_by_int2 where a > 100000000000000;
 | 
			
		||||
 | 
			
		||||
drop table lp, coll_pruning, rlp, mc3p, mc2p, boolpart, rp, coll_pruning_multi, like_op_noprune, lparted_by_int2, rparted_by_int2;
 | 
			
		||||
 | 
			
		||||
-- hash partitioning
 | 
			
		||||
create table hp (a int, b text) partition by hash (a, b);
 | 
			
		||||
create table hp0 partition of hp for values with (modulus 4, remainder 0);
 | 
			
		||||
create table hp3 partition of hp for values with (modulus 4, remainder 3);
 | 
			
		||||
create table hp1 partition of hp for values with (modulus 4, remainder 1);
 | 
			
		||||
create table hp2 partition of hp for values with (modulus 4, remainder 2);
 | 
			
		||||
 | 
			
		||||
insert into hp values (null, null);
 | 
			
		||||
insert into hp values (1, null);
 | 
			
		||||
insert into hp values (1, 'xxx');
 | 
			
		||||
insert into hp values (null, 'xxx');
 | 
			
		||||
insert into hp values (10, 'xxx');
 | 
			
		||||
insert into hp values (10, 'yyy');
 | 
			
		||||
select tableoid::regclass, * from hp order by 1;
 | 
			
		||||
 | 
			
		||||
-- partial keys won't prune, nor would non-equality conditions
 | 
			
		||||
explain (costs off) select * from hp where a = 1;
 | 
			
		||||
explain (costs off) select * from hp where b = 'xxx';
 | 
			
		||||
explain (costs off) select * from hp where a is null;
 | 
			
		||||
explain (costs off) select * from hp where b is null;
 | 
			
		||||
explain (costs off) select * from hp where a < 1 and b = 'xxx';
 | 
			
		||||
explain (costs off) select * from hp where a <> 1 and b = 'yyy';
 | 
			
		||||
 | 
			
		||||
-- pruning should work if non-null values are provided for all the keys
 | 
			
		||||
explain (costs off) select * from hp where a is null and b is null;
 | 
			
		||||
explain (costs off) select * from hp where a = 1 and b is null;
 | 
			
		||||
explain (costs off) select * from hp where a = 1 and b = 'xxx';
 | 
			
		||||
explain (costs off) select * from hp where a is null and b = 'xxx';
 | 
			
		||||
explain (costs off) select * from hp where a = 10 and b = 'xxx';
 | 
			
		||||
explain (costs off) select * from hp where a = 10 and b = 'yyy';
 | 
			
		||||
explain (costs off) select * from hp where (a = 10 and b = 'yyy') or (a = 10 and b = 'xxx') or (a is null and b is null);
 | 
			
		||||
 | 
			
		||||
-- hash partitiong pruning doesn't occur with <> operator clauses
 | 
			
		||||
explain (costs off) select * from hp where a <> 1 and b <> 'xxx';
 | 
			
		||||
 | 
			
		||||
drop table hp;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										41
									
								
								src/test/regress/sql/partition_prune_hash.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								src/test/regress/sql/partition_prune_hash.sql
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,41 @@
 | 
			
		||||
--
 | 
			
		||||
-- Test Partition pruning for HASH partitioning
 | 
			
		||||
-- We keep this as a seperate test as hash functions return
 | 
			
		||||
-- values will vary based on CPU architecture.
 | 
			
		||||
--
 | 
			
		||||
 | 
			
		||||
create table hp (a int, b text) partition by hash (a, b);
 | 
			
		||||
create table hp0 partition of hp for values with (modulus 4, remainder 0);
 | 
			
		||||
create table hp3 partition of hp for values with (modulus 4, remainder 3);
 | 
			
		||||
create table hp1 partition of hp for values with (modulus 4, remainder 1);
 | 
			
		||||
create table hp2 partition of hp for values with (modulus 4, remainder 2);
 | 
			
		||||
 | 
			
		||||
insert into hp values (null, null);
 | 
			
		||||
insert into hp values (1, null);
 | 
			
		||||
insert into hp values (1, 'xxx');
 | 
			
		||||
insert into hp values (null, 'xxx');
 | 
			
		||||
insert into hp values (10, 'xxx');
 | 
			
		||||
insert into hp values (10, 'yyy');
 | 
			
		||||
select tableoid::regclass, * from hp order by 1;
 | 
			
		||||
 | 
			
		||||
-- partial keys won't prune, nor would non-equality conditions
 | 
			
		||||
explain (costs off) select * from hp where a = 1;
 | 
			
		||||
explain (costs off) select * from hp where b = 'xxx';
 | 
			
		||||
explain (costs off) select * from hp where a is null;
 | 
			
		||||
explain (costs off) select * from hp where b is null;
 | 
			
		||||
explain (costs off) select * from hp where a < 1 and b = 'xxx';
 | 
			
		||||
explain (costs off) select * from hp where a <> 1 and b = 'yyy';
 | 
			
		||||
 | 
			
		||||
-- pruning should work if non-null values are provided for all the keys
 | 
			
		||||
explain (costs off) select * from hp where a is null and b is null;
 | 
			
		||||
explain (costs off) select * from hp where a = 1 and b is null;
 | 
			
		||||
explain (costs off) select * from hp where a = 1 and b = 'xxx';
 | 
			
		||||
explain (costs off) select * from hp where a is null and b = 'xxx';
 | 
			
		||||
explain (costs off) select * from hp where a = 10 and b = 'xxx';
 | 
			
		||||
explain (costs off) select * from hp where a = 10 and b = 'yyy';
 | 
			
		||||
explain (costs off) select * from hp where (a = 10 and b = 'yyy') or (a = 10 and b = 'xxx') or (a is null and b is null);
 | 
			
		||||
 | 
			
		||||
-- hash partitiong pruning doesn't occur with <> operator clauses
 | 
			
		||||
explain (costs off) select * from hp where a <> 1 and b <> 'xxx';
 | 
			
		||||
 | 
			
		||||
drop table hp;
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user