> On 1 June 2018 at 07:19, Pavel Stehule <pavel.steh...@gmail.com> wrote:
>
> Partition pruning is working now.
>
> Is it expected? Tested on fresh master.

That's interesting. So there are two cases:

* vlozeno > (select current_date) (pruning works)

* vlozeno > current_date (pruning doesn't work)

In pull_partkey_params when we need to extract Params matching partition key in
the first case everything is fine, we've got an expr of type Param. In the
second case we've got a SQLValueFunction, which is ignored in the code - so
eventually we think that there is nothing matching a partition key and we don't
need to apply pruning.

With the attached hacky patch it would be taken into account (although I assume
in reality SQLValueFunction should be treated somehow differently) and pruning
is happening:

=# explain analyze select * from data where vlozeno > current_date;
                                                             QUERY PLAN

------------------------------------------------------------------------------------------------------------------------------------
 Gather  (cost=1000.00..17223.38 rows=19512 width=9) (actual
time=0.456..32.952 rows=19340 loop s=1)
   Workers Planned: 2
   Workers Launched: 2
   ->  Parallel Append  (cost=0.00..14272.18 rows=8130 width=9)
(actual time=0.042..26.616 rows =6447 loops=3)
         ->  Parallel Seq Scan on data_2016  (cost=0.00..5771.19
rows=24 width=9) (never executed)
               Filter: (vlozeno > CURRENT_DATE)
         ->  Parallel Seq Scan on data_2017  (cost=0.00..5747.65
rows=23 width=9) (never executed)
               Filter: (vlozeno > CURRENT_DATE)
         ->  Parallel Seq Scan on data_other  (cost=0.00..2712.69
rows=11431 width=9) (actual time=0.032..26.031 rows=6447 loops=3)
               Filter: (vlozeno > CURRENT_DATE)
               Rows Removed by Filter: 57084
 Planning Time: 1.256 ms
 Execution Time: 35.327 ms
(13 rows)

Time: 40.291 ms
diff --git a/src/backend/partitioning/partprune.c b/src/backend/partitioning/partprune.c
index 58ec2a6..61c6c0c 100644
--- a/src/backend/partitioning/partprune.c
+++ b/src/backend/partitioning/partprune.c
@@ -2705,6 +2705,15 @@ pull_partkey_params(PartitionPruneInfo *pinfo, List *steps)
 		{
 			Expr	   *expr = lfirst(lc2);
 
+			if (IsA(expr, SQLValueFunction))
+			{
+				Param	   *param = (Param *) expr;
+
+				pinfo->execparams = bms_add_member(pinfo->execparams,
+												   param->paramid);
+				gotone = true;
+			}
+
 			if (IsA(expr, Param))
 			{
 				Param	   *param = (Param *) expr;
@@ -3038,6 +3047,7 @@ partkey_datum_from_expr(PartitionPruneContext *context,
 			return true;
 
 		case T_Param:
+		case T_SQLValueFunction:
 
 			/*
 			 * When being called from the executor we may be able to evaluate

Reply via email to