[FEAT MERGE]Patch Spatial Relationship Computation Performance Optimization & Implement of oracle spatial index

This commit is contained in:
wu-xingying
2024-06-18 01:31:46 +00:00
committed by ob-robot
parent d5629a2b36
commit 0cd742f372
107 changed files with 7016 additions and 1261 deletions

View File

@ -18,8 +18,7 @@
#include "sql/engine/ob_exec_context.h"
#include "observer/omt/ob_tenant_srs.h"
#include "ob_expr_st_intersects.h"
#include "lib/geo/ob_geo_utils.h"
#include "sql/engine/expr/ob_geo_expr_utils.h"
#include "lib/geo/ob_geo_cache.h"
using namespace oceanbase::common;
using namespace oceanbase::sql;
@ -28,7 +27,6 @@ namespace oceanbase
{
namespace sql
{
ObExprSTIntersects::ObExprSTIntersects(ObIAllocator &alloc)
: ObFuncExprOperator(alloc, T_FUN_SYS_ST_INTERSECTS, N_ST_INTERSECTS, 2, VALID_FOR_GENERATED_COL, NOT_ROW_DIMENSION)
{
@ -64,20 +62,23 @@ int ObExprSTIntersects::calc_result_type2(ObExprResType &type,
int ObExprSTIntersects::eval_st_intersects(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &res)
{
int ret = OB_SUCCESS;
//int64_t start_time = common::ObTimeUtility::current_time();
ObDatum *gis_datum1 = NULL;
ObDatum *gis_datum2 = NULL;
ObExpr *gis_arg1 = expr.args_[0];
ObExpr *gis_arg2 = expr.args_[1];
int num_args = expr.arg_cnt_;
ObObjType input_type1 = gis_arg1->datum_meta_.type_;
ObObjType input_type2 = gis_arg2->datum_meta_.type_;
ObEvalCtx::TempAllocGuard tmp_alloc_g(ctx);
common::ObArenaAllocator &temp_allocator = tmp_alloc_g.get_allocator();
bool inter_result = false;
if (OB_FAIL(gis_arg1->eval(ctx, gis_datum1)) || OB_FAIL(gis_arg2->eval(ctx, gis_datum2))) {
LOG_WARN("eval geo args failed", K(ret));
} else if (gis_datum1->is_null() || gis_datum2->is_null()) {
res.set_null();
} else {
ObGeoConstParamCache* const_param_cache = ObGeoExprUtils::get_geo_constParam_cache(expr.expr_ctx_id_, &ctx.exec_ctx_);
bool is_geo1_empty = false;
bool is_geo2_empty = false;
ObGeometry *geo1 = NULL;
@ -90,55 +91,63 @@ int ObExprSTIntersects::eval_st_intersects(const ObExpr &expr, ObEvalCtx &ctx, O
ObString wkb2 = gis_datum2->get_string();
omt::ObSrsCacheGuard srs_guard;
const ObSrsItem *srs = NULL;
bool is_geo1_cached = false;
bool is_geo2_cached = false;
ObSQLSessionInfo *session = ctx.exec_ctx_.get_my_session();
bool box_intersects = true;
if (OB_FAIL(ObTextStringHelper::read_real_string_data(temp_allocator, *gis_datum1,
gis_arg1->datum_meta_, gis_arg1->obj_meta_.has_lob_header(), wkb1))) {
LOG_WARN("fail to get real string data", K(ret), K(wkb1));
} else if (OB_FAIL(ObTextStringHelper::read_real_string_data(temp_allocator, *gis_datum2,
gis_arg2->datum_meta_, gis_arg2->obj_meta_.has_lob_header(), wkb2))) {
LOG_WARN("fail to get real string data", K(ret), K(wkb2));
} else if (OB_FAIL(ObGeoTypeUtil::get_type_srid_from_wkb(wkb1, type1, srid1))) {
if (gis_arg1->is_static_const_) {
ObGeoExprUtils::expr_get_const_param_cache(const_param_cache, geo1, srid1, is_geo1_cached, 0);
}
if (gis_arg2->is_static_const_) {
ObGeoExprUtils::expr_get_const_param_cache(const_param_cache, geo2, srid2, is_geo2_cached, 1);
}
if (!is_geo1_cached && OB_FAIL(ObGeoExprUtils::expr_prepare_build_geometry(temp_allocator, *gis_datum1, *gis_arg1, wkb1, type1, srid1))) {
if (ret == OB_ERR_GIS_INVALID_DATA) {
LOG_USER_ERROR(OB_ERR_GIS_INVALID_DATA, N_ST_INTERSECTS);
}
LOG_WARN("get type and srid from wkb failed", K(wkb1), K(ret));
} else if (OB_FAIL(ObGeoTypeUtil::get_type_srid_from_wkb(wkb2, type2, srid2))) {
} else if (!is_geo2_cached && OB_FAIL(ObGeoExprUtils::expr_prepare_build_geometry(temp_allocator, *gis_datum2, *gis_arg2, wkb2, type2, srid2))) {
if (ret == OB_ERR_GIS_INVALID_DATA) {
LOG_USER_ERROR(OB_ERR_GIS_INVALID_DATA, N_ST_INTERSECTS);
}
LOG_WARN("get type and srid from wkb failed", K(wkb2), K(ret));
} else if (srid1 != srid2) {
LOG_WARN("srid not the same", K(srid1), K(srid2));
ret = OB_ERR_GIS_DIFFERENT_SRIDS;
} else if (OB_FAIL(ObGeoExprUtils::get_srs_item(ctx, srs_guard, wkb1, srs, true, N_ST_INTERSECTS))) {
LOG_WARN("fail to get srs item", K(ret), K(wkb1));
} else if (OB_FAIL(ObGeoExprUtils::build_geometry(temp_allocator, wkb1, geo1, srs, N_ST_INTERSECTS, ObGeoBuildFlag::GEO_ALLOW_3D_DEFAULT))) {
} else if (OB_ISNULL(session)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("failed to get session", K(ret));
} else if (!is_geo1_cached && !is_geo2_cached && OB_FAIL(ObGeoExprUtils::get_srs_item(session->get_effective_tenant_id(), srs_guard, srid1, srs))) {
LOG_WARN("fail to get srs item", K(ret), K(srid1));
} else if (!is_geo1_cached && OB_FAIL(ObGeoExprUtils::build_geometry(temp_allocator, wkb1, geo1, nullptr, N_ST_INTERSECTS, ObGeoBuildFlag::GEO_ALLOW_3D_CARTESIAN))) {
LOG_WARN("get first geo by wkb failed", K(ret));
} else if (OB_FAIL(ObGeoExprUtils::build_geometry(temp_allocator, wkb2, geo2, srs, N_ST_INTERSECTS, ObGeoBuildFlag::GEO_ALLOW_3D_DEFAULT))) {
} else if (!is_geo2_cached && OB_FAIL(ObGeoExprUtils::build_geometry(temp_allocator, wkb2, geo2, nullptr, N_ST_INTERSECTS, ObGeoBuildFlag::GEO_ALLOW_3D_CARTESIAN))) {
LOG_WARN("get second geo by wkb failed", K(ret));
} else if (OB_FAIL(ObGeoExprUtils::check_empty(geo1, is_geo1_empty))
|| OB_FAIL(ObGeoExprUtils::check_empty(geo2, is_geo2_empty))) {
} else if ((!is_geo1_cached && OB_FAIL(ObGeoExprUtils::check_empty(geo1, is_geo1_empty)))
|| (!is_geo2_cached && OB_FAIL(ObGeoExprUtils::check_empty(geo2, is_geo2_empty)))) {
LOG_WARN("check geo empty failed", K(ret));
} else if (is_geo1_empty || is_geo2_empty) {
res.set_null();
} else if (OB_FAIL(ObGeoExprUtils::zoom_in_geos_for_relation(*geo1, *geo2))) {
} else if (OB_FAIL(ObGeoExprUtils::zoom_in_geos_for_relation(*geo1, *geo2, is_geo1_cached, is_geo2_cached))) {
LOG_WARN("zoom in geos failed", K(ret));
} else {
ObGeoEvalCtx gis_context(&temp_allocator, srs);
bool result = false;
if (OB_FAIL(gis_context.append_geo_arg(geo1)) || OB_FAIL(gis_context.append_geo_arg(geo2))) {
LOG_WARN("build gis context failed", K(ret), K(gis_context.get_geo_count()));
} else if (OB_FAIL(ObGeoFunc<ObGeoFuncType::Intersects>::geo_func::eval(gis_context, result))) {
LOG_WARN("eval st intersection failed", K(ret));
ObGeoExprUtils::geo_func_error_handle(ret, N_ST_INTERSECTS);
} else {
if (geo1->type() == ObGeoType::POINT
&& geo2->type() == ObGeoType::POINT
&& result == true
&& OB_FAIL(ObGeoTypeUtil::eval_point_box_intersects(srs, geo1, geo2, result))) {
LOG_WARN("eval box intersection failed", K(ret));
if (OB_NOT_NULL(const_param_cache)) {
if (gis_arg1->is_static_const_ && !is_geo1_cached &&
OB_FAIL(const_param_cache->add_const_param_cache(0, *geo1))) {
LOG_WARN("add geo1 to const cache failed", K(ret));
} else if (gis_arg2->is_static_const_ && !is_geo2_cached &&
OB_FAIL(const_param_cache->add_const_param_cache(1, *geo2))) {
LOG_WARN("add geo2 to const cache failed", K(ret));
}
res.set_bool(result);
}
if (OB_FAIL(ret)) {
} else if (OB_FAIL(ObGeoExprUtils::get_intersects_res(*geo1, *geo2, gis_arg1, gis_arg2,
const_param_cache, srs,
temp_allocator, inter_result))) {
LOG_WARN("fail to get intersects res", K(ret));
} else {
res.set_bool(inter_result);
}
}
}