Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1665,15 +1665,11 @@ explain select * from t_14887 where a = 'a'::text;
QUERY PLAN
----------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..764.38 rows=158 width=32)
-> Append (cost=0.00..762.26 rows=53 width=32)
-> Seq Scan on t0_14887 t_14887_1 (cost=0.00..254.00 rows=18 width=32)
Filter: ((a)::text = 'a'::text)
-> Seq Scan on t1_14887 t_14887_2 (cost=0.00..254.00 rows=18 width=32)
Filter: ((a)::text = 'a'::text)
-> Seq Scan on t2_14887 t_14887_3 (cost=0.00..254.00 rows=18 width=32)
Filter: ((a)::text = 'a'::text)
Optimizer: Postgres query optimizer
(9 rows)
-> Dynamic Seq Scan on t_14887
Number of partitions to scan: 3 (out of 3)
Filter: ((a)::text = 'a'::text)
Optimizer: Pivotal Optimizer (GPORCA)
(4 rows)

begin;
drop table if exists direct_test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,21 +160,18 @@ WHERE b = 42
$query$ AS qry \gset
EXPLAIN (COSTS OFF, VERBOSE)
:qry ;
INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: hash partitioning
QUERY PLAN
----------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
Output: hp.a, hp.b
-> Seq Scan on orca_static_pruning.hp0 hp
Output: hp.a, hp.b
Output: a, b
-> Dynamic Seq Scan on orca_static_pruning.hp
Output: a, b
Number of partitions to scan: 1 (out of 2)
Filter: (hp.b = 42)
Optimizer: Postgres query optimizer
(7 rows)
Optimizer: Pivotal Optimizer (GPORCA)
(8 rows)

:qry ;
INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
DETAIL: Falling back to Postgres-based planner because GPORCA does not support the following feature: hash partitioning
a | b
---+----
0 | 42
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3939,31 +3939,31 @@ explain (costs off) select * from pph_arrpart where a = '{1}';
QUERY PLAN
--------------------------------------------
Gather Motion 1:1 (slice1; segments: 1)
-> Seq Scan on pph_arrpart2 pph_arrpart
-> Dynamic Seq Scan on pph_arrpart
Number of partitions to scan: 1 (out of 2)
Filter: (a = '{1}'::integer[])
Optimizer: Postgres query optimizer
(4 rows)
Optimizer: Pivotal Optimizer (GPORCA)
(5 rows)

explain (costs off) select * from pph_arrpart where a = '{1, 2}';
QUERY PLAN
--------------------------------------------
Gather Motion 1:1 (slice1; segments: 1)
-> Seq Scan on pph_arrpart1 pph_arrpart
-> Dynamic Seq Scan on pph_arrpart
Number of partitions to scan: 1 (out of 2)
Filter: (a = '{1,2}'::integer[])
Optimizer: Postgres query optimizer
(4 rows)
Optimizer: Pivotal Optimizer (GPORCA)
(5 rows)

explain (costs off) select * from pph_arrpart where a in ('{4, 5}', '{1}');
QUERY PLAN
----------------------------------------------------------------------------
Gather Motion 2:1 (slice1; segments: 2)
-> Append
-> Seq Scan on pph_arrpart1 pph_arrpart_1
Filter: ((a = '{4,5}'::integer[]) OR (a = '{1}'::integer[]))
-> Seq Scan on pph_arrpart2 pph_arrpart_2
Filter: ((a = '{4,5}'::integer[]) OR (a = '{1}'::integer[]))
Optimizer: Postgres query optimizer
(7 rows)
Gather Motion 3:1 (slice1; segments: 3)
-> Dynamic Seq Scan on pph_arrpart
Number of partitions to scan: 2 (out of 2)
Filter: ((a = '{4,5}'::integer[]) OR (a = '{1}'::integer[]))
Optimizer: Pivotal Optimizer (GPORCA)
(5 rows)

drop table pph_arrpart;
-- enum type list partition key
Expand Down
13 changes: 8 additions & 5 deletions src/backend/gpopt/translate/CTranslatorRelcacheToDXL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2692,11 +2692,14 @@ CTranslatorRelcacheToDXL::RetrievePartKeysAndTypes(CMemoryPool *mp,
GPOS_WSZ_LIT("partitioning by expression"));
}

if (PARTITION_STRATEGY_HASH == part_type)
{
GPOS_RAISE(gpdxl::ExmaMD, gpdxl::ExmiMDObjUnsupported,
GPOS_WSZ_LIT("hash partitioning"));
}
// Hash-partitioned tables are supported for scanning only. ORCA cannot
// express a hash partition's membership rule (the satisfies_hash_partition
// call, i.e. hash(key) mod modulus = remainder) as a btree interval
// constraint, so it does no static partition pruning for hash partitions
// and simply scans every leaf partition. Range and list partitions keep
// full pruning support. Letting the strategy flow through here (instead of
// raising ExmiMDObjUnsupported) keeps such queries inside ORCA rather than
// falling back to the Postgres planner.

(*part_keys)->Append(GPOS_NEW(mp) ULONG(attno - 1));
(*part_types)->Append(GPOS_NEW(mp) CHAR(part_type));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,24 @@ class CExpressionPreprocessor
CColRefArray *pdrgpcrOutput,
ColRefToUlongMap *col_mapping);

// translate a child partition's part-constraint DXL into a CExpression over
// the root table's colrefs (NULL if the child has no stored constraint)
static CExpression *PexprPartConstraintFromChild(
CMemoryPool *mp, const IMDRelation *partrel, CColRefArray *pdrgpcrOutput,
ColRefToUlongMap *root_col_mapping);

// find a "colref = const" equality among the given conjuncts and return its
// const subexpression (NULL if none)
static CExpression *PexprColumnEqualityConst(
CExpressionArray *pdrgpexprConjuncts, const CColRef *colref);

// static hash-partition pruning: true if the leaf provably cannot contain
// any row matching the query's equality predicates on the partition key
static BOOL FHashPartitionPruned(CMemoryPool *mp, const IMDRelation *partrel,
CColRefArray *pdrgpcrOutput,
ColRefToUlongMap *root_col_mapping,
CExpressionArray *pdrgpexprConjuncts);

// swap logical select over logical project
static CExpression *PexprTransposeSelectAndProject(CMemoryPool *mp,
CExpression *pexpr);
Expand Down
12 changes: 11 additions & 1 deletion src/backend/gporca/libgpopt/src/eval/CConstExprEvaluatorDXL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "gpopt/operators/CExpression.h"
#include "gpopt/operators/CPredicateUtils.h"

#include "naucrates/md/IMDFunction.h"

using namespace gpdxl;
using namespace gpmd;
using namespace gpopt;
Expand Down Expand Up @@ -72,7 +74,15 @@ CConstExprEvaluatorDXL::PexprEval(CExpression *pexpr)
{
GPOS_ASSERT(nullptr != pexpr);

if (!CPredicateUtils::FCompareConstToConstIgnoreCast(pexpr))
// We can evaluate (a) the (const cmp const) expressions used by the
// comparator, and (b) any column-free IMMUTABLE expression (e.g.
// satisfies_hash_partition() over constants, used for hash partition
// pruning). We must not fold expressions that reference columns, nor
// volatile/stable ones, since their value is not fixed at plan time.
if (!(CPredicateUtils::FCompareConstToConstIgnoreCast(pexpr) ||
(0 == pexpr->DeriveUsedColumns()->Size() &&
IMDFunction::EfsImmutable ==
pexpr->DeriveScalarFunctionProperties()->Efs())))
{
GPOS_RAISE(gpopt::ExmaGPOPT, gpopt::ExmiEvalUnsupportedScalarExpr);
}
Expand Down
Loading
Loading