[CP] [GIS] fix gis index skyline prune

This commit is contained in:
obdev 2024-03-15 17:44:56 +00:00 committed by ob-robot
parent 4432400ddc
commit 626e7b336f
3 changed files with 75 additions and 13 deletions

View File

@ -2340,6 +2340,7 @@ int ObJoinOrder::add_access_filters(AccessPath *path,
int ObJoinOrder::check_and_extract_query_range(const uint64_t table_id,
const uint64_t index_table_id,
const IndexInfoEntry &index_info_entry,
const ObIArray<ObRawExpr*> &index_keys,
const ObIndexInfoCache &index_info_cache,
bool &contain_always_false,
@ -2350,8 +2351,10 @@ int ObJoinOrder::check_and_extract_query_range(const uint64_t table_id,
//do some quick check
bool expr_match = false; //some condition on index
contain_always_false = false;
if (OB_FAIL(check_exprs_overlap_index(restrict_infos, index_keys, expr_match))) {
if (!index_info_entry.is_index_geo() && OB_FAIL(check_exprs_overlap_index(restrict_infos, index_keys, expr_match))) {
LOG_WARN("check quals match index error", K(restrict_infos), K(index_keys));
} else if (index_info_entry.is_index_geo() && OB_FAIL(check_exprs_overlap_gis_index(restrict_infos, index_keys, expr_match))) {
LOG_WARN("check quals match gis index error", K(restrict_infos), K(index_keys));
} else if (expr_match) {
prefix_range_ids.reset();
const QueryRangeInfo *query_range_info = NULL;
@ -2427,6 +2430,7 @@ int ObJoinOrder::cal_dimension_info(const uint64_t table_id, //alias table id
LOG_WARN("failed to extract interest column ids", K(ret));
} else if (OB_FAIL(check_and_extract_query_range(table_id,
index_table_id,
*index_info_entry,
ordering_info->get_index_keys(),
index_info_cache,
contain_always_false,
@ -3618,6 +3622,48 @@ int ObJoinOrder::check_exprs_overlap_index(const ObIArray<ObRawExpr*>& quals,
return ret;
}
int ObJoinOrder::check_exprs_overlap_gis_index(const ObIArray<ObRawExpr*>& quals,
const ObIArray<ObRawExpr*>& keys,
bool &match)
{
LOG_TRACE("OPT:[CHECK GIS MATCH]", K(keys));
int ret = OB_SUCCESS;
match = false;
ObColumnRefRawExpr *cell_id = nullptr;
if (keys.empty()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("Index keys should not be empty", K(keys.count()), K(ret));
} else if (OB_ISNULL(cell_id = static_cast<ObColumnRefRawExpr *>(keys.at(0)))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("spatial Index keys should not be empty", K(keys.count()), K(ret));
} else {
for (int64_t i = 0; OB_SUCC(ret) && !match && i < quals.count(); ++i) {
ObRawExpr *expr = quals.at(i);
if (OB_ISNULL(expr)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("qual expr should not be NULL", K(expr), K(i), K(ret));
} else {
LOG_TRACE("OPT:[CHECK MATCH]", K(*expr));
ObArray<ObRawExpr*> cur_vars;
if (OB_FAIL(ObRawExprUtils::extract_column_exprs(expr, cur_vars))) {
LOG_WARN("extract_column_exprs error", K(ret));
} else {
for (int64_t j = 0; j < cur_vars.count() && !match; j++) {
ObColumnRefRawExpr *ref = static_cast<ObColumnRefRawExpr *>(cur_vars.at(j));
if (OB_NOT_NULL(ref) && ref->get_data_type() == ObGeometryType
&& cell_id->get_srs_id() == ref->get_column_id()) {
// srs_id of cellid_column is column id of which column gis index is built on
match = true;
}
}
}
}
}
}
return ret;
}
int ObJoinOrder::extract_preliminary_query_range(const ObIArray<ColumnItem> &range_columns,
const ObIArray<ObRawExpr*> &predicates,
ObIArray<ObExprConstraint> &expr_constraints,

View File

@ -1679,6 +1679,9 @@ struct NullAwareAntiJoinInfo {
int check_exprs_overlap_index(const common::ObIArray<ObRawExpr*>& quals,
const common::ObIArray<ObRawExpr*>& keys,
bool &match);
int check_exprs_overlap_gis_index(const ObIArray<ObRawExpr*>& quals,
const ObIArray<ObRawExpr*>& keys,
bool &match);
/**
*
@ -1729,6 +1732,7 @@ struct NullAwareAntiJoinInfo {
* */
int check_and_extract_query_range(const uint64_t table_id,
const uint64_t index_table_id,
const IndexInfoEntry &index_info_entry,
const ObIArray<ObRawExpr*> &index_keys,
const ObIndexInfoCache &index_info_cache,
bool &contain_always_false,

View File

@ -626,18 +626,30 @@ KEY `idx_poi_del_time_7` (`p_delete_time`) BLOCK_SIZE 16384 LOCAL
);
explain EXTENDED_NOADDR SELECT p.p_id,0 as distance FROM geek_poi_7 as p WHERE p.geohash_code like 'ws0emp%' and p.p_delete_time = 0 AND ST_Contains(p.geog_poi,_ST_GeogFromText('POINT(113.42416381835938 23.11138916015625)'));
Query Plan
===============================================
|ID|OPERATOR |NAME|EST.ROWS|EST.TIME(us)|
-----------------------------------------------
|0 |TABLE FULL SCAN|p |64 |2813 |
===============================================
=========================================================================
|ID|OPERATOR |NAME |EST.ROWS|EST.TIME(us)|
-------------------------------------------------------------------------
|0 |TABLE FULL SCAN|p(idx_geohash_code_geog_poi_7)|1 |203 |
=========================================================================
Outputs & filters:
-------------------------------------
0 - output([p.p_id], [0]), filter([p.p_delete_time = 0], [(T_OP_LIKE, p.geohash_code, 'ws0emp%', '\\')], [BOOL(ST_Contains(p.geog_poi, _ST_GeogFromText('POINT(113.42416381835938
23.11138916015625)')))])
access([p.p_id], [p.geog_poi], [p.geohash_code], [p.p_delete_time]), partitions(p0)
is_index_back=false, is_global_index=false, filter_before_indexback[false,false,false],
range_key([p.p_id]), range(MIN ; MAX)always true
is_index_back=true, is_global_index=false, filter_before_indexback[false,false,false],
range_key([p.__cellid_50], [p.__mbr_50], [p.p_id]), range(3747839687816876905,MIN,MIN ; 3747839687816876905,MAX,MAX), (3747839687816876908,MIN,MIN
; 3747839687816876908,MAX,MAX), (3747839687816876912,MIN,MIN ; 3747839687816876912,MAX,MAX), (3747839687816876864,MIN,MIN ; 3747839687816876864,MAX,MAX),
(3747839687816876800,MIN,MIN ; 3747839687816876800,MAX,MAX), (3747839687816877056,MIN,MIN ; 3747839687816877056,MAX,MAX), (3747839687816876032,MIN,MIN
; 3747839687816876032,MAX,MAX), (3747839687816888320,MIN,MIN ; 3747839687816888320,MAX,MAX), (3747839687816839168,MIN,MIN ; 3747839687816839168,MAX,MAX),
(3747839687816642560,MIN,MIN ; 3747839687816642560,MAX,MAX), (3747839687816904704,MIN,MIN ; 3747839687816904704,MAX,MAX), (3747839687813758976,MIN,MIN
; 3747839687813758976,MAX,MAX), (3747839687809564672,MIN,MIN ; 3747839687809564672,MAX,MAX), (3747839687826341888,MIN,MIN ; 3747839687826341888,MAX,MAX),
(3747839687759233024,MIN,MIN ; 3747839687759233024,MAX,MAX), (3747839687490797568,MIN,MIN ; 3747839687490797568,MAX,MAX), (3747839688564539392,MIN,MIN
; 3747839688564539392,MAX,MAX), (3747839675679637504,MIN,MIN ; 3747839675679637504,MAX,MAX), (3747839658499768320,MIN,MIN ; 3747839658499768320,MAX,MAX),
(3747839589780291584,MIN,MIN ; 3747839589780291584,MAX,MAX), (3747840414414012416,MIN,MIN ; 3747840414414012416,MAX,MAX), (3747843712948895744,MIN,MIN
; 3747843712948895744,MAX,MAX), (3747856907088429056,MIN,MIN ; 3747856907088429056,MAX,MAX), (3747909683646562304,MIN,MIN ; 3747909683646562304,MAX,MAX),
(3747839314902384640,MIN,MIN ; 3747839314902384640,MAX,MAX), (3748120789879095296,MIN,MIN ; 3748120789879095296,MAX,MAX), (3751498489599623168,MIN,MIN
; 3751498489599623168,MAX,MAX), (3765009288481734656,MIN,MIN ; 3765009288481734656,MAX,MAX), (3819052484010180608,MIN,MIN ; 3819052484010180608,MAX,MAX),
(3746994889972252672,MIN,MIN ; 3746994889972252672,MAX,MAX), (3458764513820540928,MIN,MIN ; 3458764513820540928,MAX,MAX)
Used Hint:
-------------------------------------
/*+
@ -651,7 +663,7 @@ Outline Data:
-------------------------------------
/*+
BEGIN_OUTLINE_DATA
FULL(@"SEL$1" "p"@"SEL$1")
INDEX(@"SEL$1" "p"@"SEL$1" "idx_geohash_code_geog_poi_7")
OPTIMIZER_FEATURES_ENABLE('')
END_OUTLINE_DATA
*/
@ -659,14 +671,14 @@ Optimization Info:
-------------------------------------
p:
table_rows:10002
physical_range_rows:10002
logical_range_rows:10002
physical_range_rows:3
logical_range_rows:3
index_back_rows:0
output_rows:1
output_rows:0
table_dop:1
dop_method:Table DOP
avaiable_index_name:[idx_geohash_code_geog_poi_7, idx_poi_del_time_7, geek_poi_7]
pruned_index_name:[idx_geohash_code_geog_poi_7]
unstable_index_name:[geek_poi_7]
stats version:0
dynamic sampling level:0
estimation method:[DEFAULT, STORAGE]