提交 b35c8774 编写于 作者: V Venkatesh Raghavan 提交者: Jesse Zhang

Outer Filter should not pushed down in a partition selector in subquery with...

Outer Filter should not pushed down in a partition selector in subquery with limit clause [#133827909]

The bug is in derivation of required partition propagation specification
from the child. Before this fix, we were pushing the partition
constraints below Limit which will return wrong results.
上级 32fb46dd
此差异已折叠。
......@@ -64,6 +64,14 @@ namespace gpopt
EceoSentinel
};
enum EPropogatePartConstraint
{
EppcAllowed,
EppcProhibited,
EppcSentinel
};
private:
//---------------------------------------------------------------------------
......@@ -321,7 +329,8 @@ namespace gpopt
(
IMemoryPool *pmp,
CExpressionHandle &exprhdl,
CPartitionPropagationSpec *pppsRequired
CPartitionPropagationSpec *pppsRequired,
EPropogatePartConstraint eppcPropogate
);
// pass cte requirement to the child
......
......@@ -934,7 +934,8 @@ CPhysical::PppsRequiredPushThruUnresolvedUnary
(
IMemoryPool *pmp,
CExpressionHandle &exprhdl,
CPartitionPropagationSpec *pppsRequired
CPartitionPropagationSpec *pppsRequired,
EPropogatePartConstraint eppcPropogate
)
{
GPOS_ASSERT(NULL != pppsRequired);
......@@ -962,7 +963,13 @@ CPhysical::PppsRequiredPushThruUnresolvedUnary
{
// push requirements to child node
ppimResult->AddRequiredPartPropagation(ppimReqd, ulPartIndexId, CPartIndexMap::EppraPreservePropagators);
(void) ppfmResult->FCopyPartFilter(pmp, ulPartIndexId, ppfmReqd);
if (CPhysical::EppcAllowed == eppcPropogate)
{
// for some logical operators such as limit while we push the part index map, we cannot push the constraints
// since they are NOT semantically equivalent. So only push the constraints when the operator asks this
// utility function to do so
(void) ppfmResult->FCopyPartFilter(pmp, ulPartIndexId, ppfmReqd);
}
}
}
......
......@@ -430,7 +430,7 @@ CPhysicalAgg::PppsRequired
GPOS_ASSERT(0 == ulChildIndex);
GPOS_ASSERT(NULL != pppsRequired);
return CPhysical::PppsRequiredPushThruUnresolvedUnary(pmp, exprhdl, pppsRequired);
return CPhysical::PppsRequiredPushThruUnresolvedUnary(pmp, exprhdl, pppsRequired, CPhysical::EppcAllowed);
}
//---------------------------------------------------------------------------
......
......@@ -282,7 +282,12 @@ CPhysicalLimit::PppsRequired
GPOS_ASSERT(0 == ulChildIndex);
GPOS_ASSERT(NULL != pppsRequired);
return CPhysical::PppsRequiredPushThruUnresolvedUnary(pmp, exprhdl, pppsRequired);
// limit should not push predicate below it as it will generate wrong results
// for example, the following two queries are not equivalent.
// Q1: select * from (select * from foo order by a limit 1) x where x.a = 10
// Q2: select * from (select * from foo where a = 10 order by a limit 1) x
return CPhysical::PppsRequiredPushThruUnresolvedUnary(pmp, exprhdl, pppsRequired, CPhysical::EppcProhibited);
}
//---------------------------------------------------------------------------
......
......@@ -413,7 +413,7 @@ CPhysicalSequenceProject::PppsRequired
GPOS_ASSERT(0 == ulChildIndex);
GPOS_ASSERT(NULL != pppsRequired);
return CPhysical::PppsRequiredPushThruUnresolvedUnary(pmp, exprhdl, pppsRequired);
return CPhysical::PppsRequiredPushThruUnresolvedUnary(pmp, exprhdl, pppsRequired, CPhysical::EppcAllowed);
}
//---------------------------------------------------------------------------
......
......@@ -228,7 +228,7 @@ CPhysicalSort::PppsRequired
GPOS_ASSERT(0 == ulChildIndex);
GPOS_ASSERT(NULL != pppsRequired);
return CPhysical::PppsRequiredPushThruUnresolvedUnary(pmp, exprhdl, pppsRequired);
return CPhysical::PppsRequiredPushThruUnresolvedUnary(pmp, exprhdl, pppsRequired, CPhysical::EppcAllowed);
}
//---------------------------------------------------------------------------
......
......@@ -28,6 +28,7 @@ ULONG CPartTblTest::m_ulPartTblTestCounter = 0; // start from first test
// minidump files
const CHAR *rgszPartTblFileNames[] =
{
"../data/dxl/minidump/DonotPushPartConstThruLimit.mdp",
"../data/dxl/minidump/PartTbl-DPE-Correlated-NLOuter.mdp",
"../data/dxl/minidump/Select-Over-PartTbl.mdp",
"../data/dxl/minidump/PartTbl-DPE.mdp",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册