[GIS] fix gis index rebuild in partition table

This commit is contained in:
helloamateur 2024-07-12 11:22:24 +00:00 committed by ob-robot
parent 4eec8a8049
commit 62bbae517f
4 changed files with 51 additions and 4 deletions

View File

@ -3095,7 +3095,7 @@ int ObTableScanOp::inner_get_next_spatial_index_row()
spat_index_.spat_rows_->reuse();
spat_index_.spat_row_index_ = 0;
const ObExprPtrIArray &exprs = MY_SPEC.output_;
ObExpr *expr = exprs.at(3);
ObExpr *expr = exprs.at(spat_index_.geo_idx_);
ObDatum *in_datum = NULL;
ObString geo_wkb;
if (OB_FAIL(expr->eval(eval_ctx_, in_datum))) {
@ -3184,6 +3184,25 @@ int ObTableScanOp::init_spatial_index_rows()
spat_index_.spat_rows_ = new(buf) ObDomainIndexRow();
spat_index_.mbr_buffer_ = mbr_buffer;
spat_index_.obj_buffer_ = obj_buf;
const ObExprPtrIArray &exprs = MY_SPEC.output_;
const uint8_t spatial_expr_cnt = 3;
uint8_t cnt = 0;
for (uint32_t i = 0; i < exprs.count() && cnt < spatial_expr_cnt; i++) {
if (exprs.at(i)->type_ == T_FUN_SYS_SPATIAL_CELLID) {
spat_index_.cell_idx_ = i;
cnt++;
} else if (exprs.at(i)->type_ == T_FUN_SYS_SPATIAL_MBR) {
spat_index_.mbr_idx_ = i;
cnt++;
} else if (exprs.at(i)->datum_meta_.type_ == ObGeometryType) {
spat_index_.geo_idx_ = i;
cnt++;
}
}
if (cnt != spatial_expr_cnt) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("invalid spatial index exprs", K(ret), K(cnt));
}
}
return ret;
}
@ -3199,7 +3218,8 @@ int ObTableScanOp::fill_generated_cellid_mbr(const ObObj &cellid, const ObObj &m
for (uint8_t i = 0; i < 2 && OB_SUCC(ret); i++) {
ObObjDatumMapType type = i == 0 ? OBJ_DATUM_8BYTE_DATA : OBJ_DATUM_STRING;
const ObObj &value = i == 0 ? cellid : mbr;
ObExpr *expr = exprs.at(i);
uint32_t idx = i == 0 ? spat_index_.cell_idx_ : spat_index_.mbr_idx_;
ObExpr *expr = exprs.at(idx);
ObDatum *datum = &expr->locate_datum_for_write(get_eval_ctx());
ObEvalInfo *eval_info = &expr->get_eval_info(get_eval_ctx());
if (OB_FAIL(datum->from_obj(value, type))) {

View File

@ -73,13 +73,19 @@ public:
spat_rows_(nullptr),
spat_row_index_(0),
mbr_buffer_(nullptr),
obj_buffer_(nullptr)
obj_buffer_(nullptr),
geo_idx_(0),
cell_idx_(0),
mbr_idx_(0)
{}
~ObSpatialIndexCache() {};
ObDomainIndexRow *spat_rows_;
uint8_t spat_row_index_;
void *mbr_buffer_;
void *obj_buffer_;
uint32_t geo_idx_;
uint32_t cell_idx_;
uint32_t mbr_idx_;
};
//for the oracle virtual agent table access the real table

View File

@ -373,3 +373,15 @@ Outputs & filters:
MAX,MAX), (1154047404513689600,MIN,MIN ; 1154047404513689600,MAX,MAX), (1157425104234217472,MIN,MIN ; 1157425104234217472,MAX,MAX), (1170935903116328960,
MIN,MIN ; 1170935903116328960,MAX,MAX), (1224979098644774912,MIN,MIN ; 1224979098644774912,MAX,MAX), (1441151880758558720,MIN,MIN ; 1441151880758558720,
MAX,MAX), (1152921504606846976,MIN,MIN ; 1152921504606846976,MAX,MAX), (1152921504606846977,MIN,MIN ; 1152921504606846983,MAX,MAX)
DROP TABLE IF EXISTS partition_t1;
create table partition_t1(c1 int primary key, g geometry not null srid 0, g1 geometry srid 0) partition by hash(c1) partitions 2;
insert into partition_t1 values (0, st_geomfromtext('point(1 1)'), st_geomfromtext('point(2 2)'));
insert into partition_t1 values (1, st_geomfromtext('point(1 0)'), st_geomfromtext('point(2 2)'));
select /*+index(partition_t1 idx)*/ st_astext(g) from partition_t1 where st_intersects(g, st_geomfromtext('point(1 1)'));
st_astext(g)
POINT(1 1)
create spatial index idx on partition_t1 (g) local;
select /*+index(partition_t1 idx)*/ st_astext(g) from partition_t1 where st_intersects(g, st_geomfromtext('point(1 1)'));
st_astext(g)
POINT(1 1)
drop table partition_t1;

View File

@ -117,4 +117,13 @@ explain select /*+ parallel(1) */ count(*) from geo_maxpt_coords_100y_2 where s
explain select /*+ parallel(3) */ count(*) from geo_maxpt_coords_100y_2 where st_intersects(geo_maxpt_coords_100y_2.geo_pwkt, st_geomfromtext('polygon((0 0,5 0,5 5,0 5,0 0))', 0));
--disable_warnings
DROP TABLE IF EXISTS partition_t1;
--enable_warnings
create table partition_t1(c1 int primary key, g geometry not null srid 0, g1 geometry srid 0) partition by hash(c1) partitions 2;
insert into partition_t1 values (0, st_geomfromtext('point(1 1)'), st_geomfromtext('point(2 2)'));
insert into partition_t1 values (1, st_geomfromtext('point(1 0)'), st_geomfromtext('point(2 2)'));
select /*+index(partition_t1 idx)*/ st_astext(g) from partition_t1 where st_intersects(g, st_geomfromtext('point(1 1)'));
create spatial index idx on partition_t1 (g) local;
select /*+index(partition_t1 idx)*/ st_astext(g) from partition_t1 where st_intersects(g, st_geomfromtext('point(1 1)'));
drop table partition_t1;