未验证 提交 29025668 编写于 作者: H Hans Zeller 提交者: GitHub

Prevent fallback when using array comparisons with btree indexes (#553)

We only support array comparison predicates on bitmap index scans, not on
btree index scans or index scans of other types. However, ORCA was attempting
to generate such plans, leading to a fallback to planner.

With the fix, we will only consider bitmap indexes for array comparison
predicates. This should avoid the fallback.

Here is a simple test case:

```
drop table if exists foo;
create table foo (a int, b int) distributed by (a);
insert into foo values (1,1);
create index foo_ix on foo using btree (b);

set optimizer_print_plan to on;
set client_min_messages to 'log';

-- before: btree index scan with an array comparison, fallback
-- after: file scan with array comparison, ORCA plan
explain select * from foo where b in (1, 3);

-- before: btree index scan with array comparison, fallback, planner error in 5X
-- after: file scan with array comparison, ORCA plan, succeeds in 5X
explain update foo set a = 1 where b in (1, 3);
```
上级 bcc826e8
......@@ -5,7 +5,7 @@ project(gpopt LANGUAGES CXX C)
set(CMAKE_CXX_STANDARD 98)
set(GPORCA_VERSION_MAJOR 3)
set(GPORCA_VERSION_MINOR 81)
set(GPORCA_VERSION_MINOR 82)
set(GPORCA_VERSION_PATCH 0)
set(GPORCA_VERSION_STRING "${GPORCA_VERSION_MAJOR}.${GPORCA_VERSION_MINOR}.${GPORCA_VERSION_PATCH}")
......
......@@ -302,10 +302,10 @@ SELECT * FROM test WHERE a in (1, 47);
</dxl:LogicalGet>
</dxl:LogicalSelect>
</dxl:Query>
<dxl:Plan Id="0" SpaceSize="2">
<dxl:Plan Id="0" SpaceSize="1">
<dxl:GatherMotion InputSegments="0,1,2" OutputSegments="-1">
<dxl:Properties>
<dxl:Cost StartupCost="0" TotalCost="6.000228" Rows="2.000000" Width="4"/>
<dxl:Cost StartupCost="0" TotalCost="448.213950" Rows="2.000000" Width="4"/>
</dxl:Properties>
<dxl:ProjList>
<dxl:ProjElem ColId="0" Alias="a">
......@@ -314,17 +314,16 @@ SELECT * FROM test WHERE a in (1, 47);
</dxl:ProjList>
<dxl:Filter/>
<dxl:SortingColumnList/>
<dxl:IndexScan IndexScanDirection="Forward">
<dxl:TableScan>
<dxl:Properties>
<dxl:Cost StartupCost="0" TotalCost="6.000193" Rows="2.000000" Width="4"/>
<dxl:Cost StartupCost="0" TotalCost="448.213920" Rows="2.000000" Width="4"/>
</dxl:Properties>
<dxl:ProjList>
<dxl:ProjElem ColId="0" Alias="a">
<dxl:Ident ColId="0" ColName="a" TypeMdid="0.23.1.0"/>
</dxl:ProjElem>
</dxl:ProjList>
<dxl:Filter/>
<dxl:IndexCondList>
<dxl:Filter>
<dxl:ArrayComp OperatorName="=" OperatorMdid="0.96.1.0" OperatorType="Any">
<dxl:Ident ColId="0" ColName="a" TypeMdid="0.23.1.0"/>
<dxl:Array ArrayType="0.1007.1.0" ElementType="0.23.1.0" MultiDimensional="false">
......@@ -332,8 +331,7 @@ SELECT * FROM test WHERE a in (1, 47);
<dxl:ConstValue TypeMdid="0.23.1.0" Value="47"/>
</dxl:Array>
</dxl:ArrayComp>
</dxl:IndexCondList>
<dxl:IndexDescriptor Mdid="0.41692.1.0" IndexName="test_index"/>
</dxl:Filter>
<dxl:TableDescriptor Mdid="0.41665.1.1" TableName="test">
<dxl:Columns>
<dxl:Column ColId="0" Attno="1" ColName="a" TypeMdid="0.23.1.0"/>
......@@ -346,7 +344,7 @@ SELECT * FROM test WHERE a in (1, 47);
<dxl:Column ColId="7" Attno="-8" ColName="gp_segment_id" TypeMdid="0.23.1.0"/>
</dxl:Columns>
</dxl:TableDescriptor>
</dxl:IndexScan>
</dxl:TableScan>
</dxl:GatherMotion>
</dxl:Plan>
</dxl:Thread>
......
......@@ -2069,7 +2069,7 @@ CPredicateUtils::PexprIndexLookup
{
cmptype = CScalarCmp::PopConvert(pexprScalar->Pop())->ParseCmpType();
}
else if (CUtils::FScalarArrayCmp(pexprScalar))
else if (CUtils::FScalarArrayCmp(pexprScalar) && IMDIndex::EmdindBitmap == pmdindex->IndexType())
{
cmptype = CUtils::ParseCmpType(CScalarArrayCmp::PopConvert(pexprScalar->Pop())->MdIdOp());
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册