From 82c173f56077bf2044b8b8dc83c9ba72b5a5b352 Mon Sep 17 00:00:00 2001 From: wu-xingying <729224612@qq.com> Date: Mon, 22 Apr 2024 17:41:52 +0000 Subject: [PATCH] cp open-source ut fail & geo 4016 union --- src/sql/resolver/expr/ob_raw_expr.cpp | 73 +++++++++++-------- src/sql/resolver/expr/ob_raw_expr.h | 1 + src/sql/rewrite/ob_query_range.cpp | 7 +- .../r/mysql/geometry_ddl_mysql.result | 7 ++ .../r/mysql/geometry_index_mysql.result | 20 +++++ .../geometry/t/geometry_ddl_mysql.test | 13 +++- .../geometry/t/geometry_index_mysql.test | 12 ++- unittest/share/test_geo_bin.cpp | 23 ++++-- unittest/share/test_geo_common.cpp | 4 +- 9 files changed, 117 insertions(+), 43 deletions(-) diff --git a/src/sql/resolver/expr/ob_raw_expr.cpp b/src/sql/resolver/expr/ob_raw_expr.cpp index 9ce8c92a9..1240e9582 100644 --- a/src/sql/resolver/expr/ob_raw_expr.cpp +++ b/src/sql/resolver/expr/ob_raw_expr.cpp @@ -689,40 +689,53 @@ bool ObRawExpr::is_priv_geo_expr() const return IS_PRIV_GEO_OP(get_expr_type()); } +// has already been confirmed that the result type is geometry. ObGeoType ObRawExpr::get_geo_expr_result_type() const { - if (!is_geo_expr() && T_FUN_SYS_CAST != this->get_expr_type()) { - LOG_WARN_RET(OB_ERR_UNEXPECTED, "Expr is not a geo expr"); - return ObGeoType::GEOTYPEMAX; - } else { - switch (this->get_expr_type()) { - case T_FUN_SYS_CAST: { - int ret = OB_SUCCESS; - ObGeoType geo_type = ObGeoType::GEOTYPEMAX; - if (OB_FAIL(get_geo_cast_result_type(geo_type))) { - LOG_WARN("could not get geo type from cast", K(ret)); - } - return geo_type; - } - case T_FUN_SYS_POINT: - case T_FUN_SYS_ST_CENTROID: - return ObGeoType::POINT; - case T_FUN_SYS_LINESTRING: - return ObGeoType::LINESTRING; - case T_FUN_SYS_MULTIPOINT: - return ObGeoType::MULTIPOINT; - case T_FUN_SYS_MULTILINESTRING: - return ObGeoType::MULTILINESTRING; - case T_FUN_SYS_POLYGON: - return ObGeoType::POLYGON; - case T_FUN_SYS_MULTIPOLYGON: - return ObGeoType::MULTIPOLYGON; - case T_FUN_SYS_GEOMCOLLECTION: - return ObGeoType::GEOMETRYCOLLECTION; - default: - return ObGeoType::GEOMETRY; + ObGeoType geo_type = ObGeoType::GEOTYPEMAX; + switch (this->get_expr_type()) { + case T_FUN_SYS_CAST: { + int ret = OB_SUCCESS; + if (OB_FAIL(get_geo_cast_result_type(geo_type))) { + geo_type = ObGeoType::GEOTYPEMAX; + } + break; + } + case T_FUN_SYS_POINT: + case T_FUN_SYS_ST_CENTROID: { + geo_type = ObGeoType::POINT; + break; + } + case T_FUN_SYS_LINESTRING: { + geo_type = ObGeoType::LINESTRING; + break; + } + case T_FUN_SYS_MULTIPOINT: { + geo_type = ObGeoType::MULTIPOINT; + break; + } + case T_FUN_SYS_MULTILINESTRING: { + geo_type = ObGeoType::MULTILINESTRING; + break; + } + case T_FUN_SYS_POLYGON: { + geo_type = ObGeoType::POLYGON; + break; + } + case T_FUN_SYS_MULTIPOLYGON: { + geo_type = ObGeoType::MULTIPOLYGON; + break; + } + case T_FUN_SYS_GEOMCOLLECTION: { + geo_type = ObGeoType::GEOMETRYCOLLECTION; + break; + } + default: { + geo_type = ObGeoType::GEOMETRY; + break; } } + return geo_type; } int ObRawExpr::get_geo_cast_result_type(ObGeoType& geo_type) const diff --git a/src/sql/resolver/expr/ob_raw_expr.h b/src/sql/resolver/expr/ob_raw_expr.h index 8d4a97fec..501be94a3 100644 --- a/src/sql/resolver/expr/ob_raw_expr.h +++ b/src/sql/resolver/expr/ob_raw_expr.h @@ -2755,6 +2755,7 @@ public: bool is_xml_column() const { return ob_is_xml_pl_type(get_data_type(), get_udt_id()) || ob_is_xml_sql_type(get_data_type(), get_subschema_id()); } + bool is_geo_column() const { return get_data_type() == ObObjType::ObGeometryType; } bool is_udt_hidden_column() const { return is_hidden_column() && get_udt_set_id() > 0;} inline common::ObGeoType get_geo_type() const { return static_cast(srs_info_.geo_type_); } diff --git a/src/sql/rewrite/ob_query_range.cpp b/src/sql/rewrite/ob_query_range.cpp index fd3764349..910deb825 100644 --- a/src/sql/rewrite/ob_query_range.cpp +++ b/src/sql/rewrite/ob_query_range.cpp @@ -3673,6 +3673,8 @@ int ObQueryRange::pre_extract_geo_op(const ObOpRawExpr *geo_expr, GET_ALWAYS_TRUE_OR_FALSE(true, out_key_part); } else if (l_expr->has_flag(IS_DYNAMIC_PARAM) && r_expr->has_flag(IS_DYNAMIC_PARAM)) { GET_ALWAYS_TRUE_OR_FALSE(true, out_key_part); + } else if (!l_expr->has_flag(CNT_COLUMN) && !r_expr->has_flag(CNT_COLUMN)) { + GET_ALWAYS_TRUE_OR_FALSE(true, out_key_part); } else { op_type = get_geo_relation(expr->get_expr_type()); if (OB_UNLIKELY(r_expr->has_flag(CNT_COLUMN))) { @@ -3693,7 +3695,10 @@ int ObQueryRange::pre_extract_geo_op(const ObOpRawExpr *geo_expr, LOG_WARN("failed to find column item", K(ret), KPC(r_expr), KPC(l_expr)); } - if (OB_SUCC(ret)) { + if (OB_FAIL(ret)) { + } else if (!column_item->is_geo_column()) { // not geo column, do not extract geo query range + GET_ALWAYS_TRUE_OR_FALSE(true, out_key_part); + } else { bool is_cellid_col = false; uint64_t column_id = column_item->get_column_id(); ObGeoColumnInfo column_info; diff --git a/tools/deploy/mysql_test/test_suite/geometry/r/mysql/geometry_ddl_mysql.result b/tools/deploy/mysql_test/test_suite/geometry/r/mysql/geometry_ddl_mysql.result index 4baf465d4..3b4829adb 100644 --- a/tools/deploy/mysql_test/test_suite/geometry/r/mysql/geometry_ddl_mysql.result +++ b/tools/deploy/mysql_test/test_suite/geometry/r/mysql/geometry_ddl_mysql.result @@ -638,3 +638,10 @@ ALTER TABLE test_wrong_table MODIFY COLUMN the_geom varbinary(200) NOT NULL; ERROR 42000: A SPATIAL index may only contain a geometrical type column. DELETE FROM test_wrong_table; drop table test_wrong_table; +bugfix: 55864433 +drop table if exists t1; +drop view if exists v1; +create TABLE t1(pt POINT); +CREATE VIEW v1 AS (SELECT * FROM t1 ) UNION (SELECT * FROM t1 ); +drop table t1; +drop view v1; diff --git a/tools/deploy/mysql_test/test_suite/geometry/r/mysql/geometry_index_mysql.result b/tools/deploy/mysql_test/test_suite/geometry/r/mysql/geometry_index_mysql.result index f4ccb4e61..cee6e92bf 100644 --- a/tools/deploy/mysql_test/test_suite/geometry/r/mysql/geometry_index_mysql.result +++ b/tools/deploy/mysql_test/test_suite/geometry/r/mysql/geometry_index_mysql.result @@ -224,3 +224,23 @@ drop table if exists spatial_index; CREATE TABLE spatial_index (i INT, g GEOMETRY NOT NULL SRID 4326, PRIMARY KEY (i), SPATIAL KEY (g))with column group ( each column); select i, st_astext(g) from spatial_index where ST_Intersects(g, ST_GEOMFROMTEXT('POINT(2 2)', 4326)); i st_astext(g) +drop table if exists t1; +create table t1(a int,b int); +create index idx1 on t1(a); +SELECT st_astext(a) FROM t1 WHERE st_equals(a, point(7, 7)); +st_astext(a) +explain SELECT st_astext(a) FROM t1 WHERE st_equals(a, point(7, 7)); +Query Plan +=============================================== +|ID|OPERATOR |NAME|EST.ROWS|EST.TIME(us)| +----------------------------------------------- +|0 |TABLE FULL SCAN|t1 |1 |22 | +=============================================== +Outputs & filters: +------------------------------------- + 0 - output([st_astext(cast(t1.a, LONGTEXT(536870911)))]), filter([st_equals(cast(t1.a, VARCHAR(1048576)), point(cast(7, DOUBLE(-1, -1)), cast(7, DOUBLE(-1, + -1))))]), rowset=8 + access([t1.a]), partitions(p0) + is_index_back=false, is_global_index=false, filter_before_indexback[false], + range_key([t1.__pk_increment]), range(MIN ; MAX)always true +drop table t1; diff --git a/tools/deploy/mysql_test/test_suite/geometry/t/geometry_ddl_mysql.test b/tools/deploy/mysql_test/test_suite/geometry/t/geometry_ddl_mysql.test index f8199af82..f7cac6956 100644 --- a/tools/deploy/mysql_test/test_suite/geometry/t/geometry_ddl_mysql.test +++ b/tools/deploy/mysql_test/test_suite/geometry/t/geometry_ddl_mysql.test @@ -799,4 +799,15 @@ INSERT INTO test_wrong_table (id, the_geom) VALUES (21, st_geomfromtext('POLYGON --error 1687 ALTER TABLE test_wrong_table MODIFY COLUMN the_geom varbinary(200) NOT NULL; DELETE FROM test_wrong_table; -drop table test_wrong_table; \ No newline at end of file +drop table test_wrong_table; + +--echo bugfix: 55864433 +--disable_warnings +drop table if exists t1; +--disable_warnings +drop view if exists v1; +create TABLE t1(pt POINT); +CREATE VIEW v1 AS (SELECT * FROM t1 ) UNION (SELECT * FROM t1 ); + +drop table t1; +drop view v1; \ No newline at end of file diff --git a/tools/deploy/mysql_test/test_suite/geometry/t/geometry_index_mysql.test b/tools/deploy/mysql_test/test_suite/geometry/t/geometry_index_mysql.test index 4367cd721..4c198baf2 100644 --- a/tools/deploy/mysql_test/test_suite/geometry/t/geometry_index_mysql.test +++ b/tools/deploy/mysql_test/test_suite/geometry/t/geometry_index_mysql.test @@ -247,4 +247,14 @@ if (1) { drop table if exists spatial_index; --enable_warnings CREATE TABLE spatial_index (i INT, g GEOMETRY NOT NULL SRID 4326, PRIMARY KEY (i), SPATIAL KEY (g))with column group ( each column); -select i, st_astext(g) from spatial_index where ST_Intersects(g, ST_GEOMFROMTEXT('POINT(2 2)', 4326)); \ No newline at end of file +select i, st_astext(g) from spatial_index where ST_Intersects(g, ST_GEOMFROMTEXT('POINT(2 2)', 4326)); + +#bugfix: 56294148 & 56301820 +--disable_warnings +drop table if exists t1; +--enable_warnings +create table t1(a int,b int); +create index idx1 on t1(a); +SELECT st_astext(a) FROM t1 WHERE st_equals(a, point(7, 7)); +explain SELECT st_astext(a) FROM t1 WHERE st_equals(a, point(7, 7)); +drop table t1; \ No newline at end of file diff --git a/unittest/share/test_geo_bin.cpp b/unittest/share/test_geo_bin.cpp index 1bb791fae..57ebe0535 100644 --- a/unittest/share/test_geo_bin.cpp +++ b/unittest/share/test_geo_bin.cpp @@ -5322,6 +5322,7 @@ TEST_F(TestGeoBin, sdo_point_3d) { geo_3d.set_data(wkb2); ObSdoGeoObject geo3; ASSERT_EQ(OB_SUCCESS, geo_3d.to_sdo_geometry(geo3)); + geo3.set_srid(geo.get_srid()); ASSERT_EQ(geo == geo3, true); ObString geo_json; @@ -5389,6 +5390,7 @@ TEST_F(TestGeoBin, sdo_linestring_3d) { geo_3d.set_data(wkb); ObSdoGeoObject geo3; ASSERT_EQ(OB_SUCCESS, geo_3d.to_sdo_geometry(geo3)); + geo3.set_srid(geo.get_srid()); ASSERT_EQ(geo == geo3, true); ObString geo_json; @@ -5484,6 +5486,7 @@ TEST_F(TestGeoBin, sdo_polygon_3d) { geo_3d.set_data(wkb); ObSdoGeoObject geo3; ASSERT_EQ(OB_SUCCESS, geo_3d.to_sdo_geometry(geo3)); + geo3.set_srid(geo.get_srid()); ASSERT_EQ(geo == geo3, true); ObString geo_json; @@ -5551,6 +5554,7 @@ TEST_F(TestGeoBin, sdo_multipoint_3d) { geo_3d.set_data(wkb); ObSdoGeoObject geo3; ASSERT_EQ(OB_SUCCESS, geo_3d.to_sdo_geometry(geo3)); + geo3.set_srid(geo.get_srid()); ASSERT_EQ(geo == geo3, true); ObString geo_json; @@ -5634,6 +5638,7 @@ TEST_F(TestGeoBin, sdo_multilinestring_3d) { geo_3d.set_data(wkb); ObSdoGeoObject geo3; ASSERT_EQ(OB_SUCCESS, geo_3d.to_sdo_geometry(geo3)); + geo3.set_srid(geo.get_srid()); ASSERT_EQ(geo == geo3, true); ObString geo_json; @@ -5739,6 +5744,7 @@ TEST_F(TestGeoBin, sdo_multipolygon_3d) { geo_3d.set_data(wkb); ObSdoGeoObject geo3; ASSERT_EQ(OB_SUCCESS, geo_3d.to_sdo_geometry(geo3)); + geo3.set_srid(geo.get_srid()); ASSERT_EQ(geo == geo3, true); ObString geo_json; @@ -5857,6 +5863,7 @@ TEST_F(TestGeoBin, sdo_collection_3d) { geo_3d.set_data(wkb); ObSdoGeoObject geo3; ASSERT_EQ(OB_SUCCESS, geo_3d.to_sdo_geometry(geo3)); + geo3.set_srid(geo.get_srid()); ASSERT_EQ(geo == geo3, true); ObString geo_json; @@ -6069,28 +6076,28 @@ TEST_F(TestGeoBin, elevation_visitor) { ObArenaAllocator allocator(ObModIds::TEST); elevation_visitor_checker(allocator, "LINESTRING Z (0 0 0, 10 10 10)", "GEOMETRYCOLLECTION Z EMPTY", "MULTIPOINT(-1 11, 11 11, 0 10, 5 10, 10 10, 0 5, 5 5, 10 5, 0 0, 5 0, 10 0, -1 -1, 5 -1, 11 -1)", - "MULTIPOINT Z (-1 11 5,11 11 10,0 10 5,5 10 5,10 10 10,0 5 5,5 5 5,10 5 5,0 0 0,5 0 5,10 0 5,-1 -1 0,5 -1 5,11 -1 5)"); + "MULTIPOINT Z ((-1 11 5),(11 11 10),(0 10 5),(5 10 5),(10 10 10),(0 5 5),(5 5 5),(10 5 5),(0 0 0),(5 0 5),(10 0 5),(-1 -1 0),(5 -1 5),(11 -1 5))"); elevation_visitor_checker(allocator, "POLYGON Z ((1 6 50, 9 6 60, 9 4 50, 1 4 40, 1 6 50))", "GEOMETRYCOLLECTION Z EMPTY", "MULTIPOINT(0 10,5 10,10 10,0 5,5 5,10 5,0 4,5 4,10 4,0 0,5 0,10 0)", - "MULTIPOINT Z (0 10 50,5 10 50,10 10 60,0 5 50,5 5 50,10 5 50,0 4 40,5 4 50,10 4 50,0 0 40,5 0 50,10 0 50)"); + "MULTIPOINT Z ((0 10 50),(5 10 50),(10 10 60),(0 5 50),(5 5 50),(10 5 50),(0 4 40),(5 4 50),(10 4 50),(0 0 40),(5 0 50),(10 0 50))"); elevation_visitor_checker(allocator, "MULTILINESTRING Z ((0 0 0, 10 10 8), (1 2 2, 9 8 6))", "GEOMETRYCOLLECTION Z EMPTY", "MULTIPOINT(-1 11,11 11,0 10,5 10,10 10,0 5,5 5,10 5,0 0,5 0,10 0,-1 -1,5 -1,11 -1)", - "MULTIPOINT Z (-1 11 4,11 11 7,0 10 4,5 10 4,10 10 7,0 5 4,5 5 4,10 5 4,0 0 1,5 0 4,10 0 4,-1 -1 1,5 -1 4,11 -1 4)"); + "MULTIPOINT Z ((-1 11 4),(11 11 7),(0 10 4),(5 10 4),(10 10 7),(0 5 4),(5 5 4),(10 5 4),(0 0 1),(5 0 4),(10 0 4),(-1 -1 1),(5 -1 4),(11 -1 4))"); elevation_visitor_checker(allocator, "LINESTRING Z (0 0 0, 10 10 8)", "LINESTRING Z (1 2 2, 9 8 6)", "MULTIPOINT(-1 11,11 11,0 10,5 10,10 10,0 5,5 5,10 5,0 0,5 0,10 0,-1 -1,5 -1,11 -1)", - "MULTIPOINT Z (-1 11 4,11 11 7,0 10 4,5 10 4,10 10 7,0 5 4,5 5 4,10 5 4,0 0 1,5 0 4,10 0 4,-1 -1 1,5 -1 4,11 -1 4)"); + "MULTIPOINT Z ((-1 11 4),(11 11 7),(0 10 4),(5 10 4),(10 10 7),(0 5 4),(5 5 4),(10 5 4),(0 0 1),(5 0 4),(10 0 4),(-1 -1 1),(5 -1 4),(11 -1 4))"); elevation_visitor_checker(allocator, "LINESTRING Z (0 5 0, 10 5 10)", "GEOMETRYCOLLECTION Z EMPTY", "MULTIPOINT(0 10,5 10,10 10,0 5,5 5,10 5,0 0,5 0,10 0)", - "MULTIPOINT Z (0 10 0,5 10 5,10 10 10,0 5 0,5 5 5,10 5 10,0 0 0,5 0 5,10 0 10)"); + "MULTIPOINT Z ((0 10 0),(5 10 5),(10 10 10),(0 5 0),(5 5 5),(10 5 10),(0 0 0),(5 0 5),(10 0 10))"); elevation_visitor_checker(allocator, "LINESTRING Z (5 0 0, 5 10 10)", "GEOMETRYCOLLECTION Z EMPTY", "MULTIPOINT(0 10,5 10,10 10,0 5,5 5,10 5,0 0,5 0,10 0)", - "MULTIPOINT Z (0 10 10,5 10 10,10 10 10,0 5 5,5 5 5,10 5 5,0 0 0,5 0 0,10 0 0)"); + "MULTIPOINT Z ((0 10 10),(5 10 10),(10 10 10),(0 5 5),(5 5 5),(10 5 5),(0 0 0),(5 0 0),(10 0 0))"); elevation_visitor_checker(allocator, "POINT Z (5 5 5)", "GEOMETRYCOLLECTION Z EMPTY", "MULTIPOINT(0 9,5 9,9 9,0 5,5 5,9 5,0 0,5 0,9 0)", - "MULTIPOINT Z (0 9 5,5 9 5,9 9 5,0 5 5,5 5 5,9 5 5,0 0 5,5 0 5,9 0 5)"); + "MULTIPOINT Z ((0 9 5),(5 9 5),(9 9 5),(0 5 5),(5 5 5),(9 5 5),(0 0 5),(5 0 5),(9 0 5))"); elevation_visitor_checker(allocator, "MULTIPOINT Z ((5 5 5), (5 5 9))", "GEOMETRYCOLLECTION Z EMPTY", "MULTIPOINT(0 9,5 9,9 9,0 5,5 5,9 5,0 0,5 0,9 0)", - "MULTIPOINT Z (0 9 7,5 9 7,9 9 7,0 5 7,5 5 7,9 5 7,0 0 7,5 0 7,9 0 7)"); + "MULTIPOINT Z ((0 9 7),(5 9 7),(9 9 7),(0 5 7),(5 5 7),(9 5 7),(0 0 7),(5 0 7),(9 0 7))"); elevation_visitor_checker(allocator, "LINESTRING Z (0 0 0, 10 10 10)", "GEOMETRYCOLLECTION Z EMPTY", "LINESTRING (1 1, 9 9)", "LINESTRING Z (1 1 0,9 9 10)"); diff --git a/unittest/share/test_geo_common.cpp b/unittest/share/test_geo_common.cpp index 613489a6d..0a5972d40 100644 --- a/unittest/share/test_geo_common.cpp +++ b/unittest/share/test_geo_common.cpp @@ -171,7 +171,7 @@ void build_obj_double(double num, ObArenaAllocator &allocator, ObObj &res) { double_to_number(num, allocator, nmb); res.set_number(nmb); } - +#ifdef OB_BUILD_ORACLE_PL void mock_write_sdo_elem_info(ObArray &elem_info, common::ObIAllocator &ctx_allocator, common::ObObj &result) { pl::ObPLVArray *elem_array = reinterpret_cast(ctx_allocator.alloc(sizeof(pl::ObPLVArray))); @@ -303,7 +303,7 @@ TEST_F(TestGeoCommon, sql_udt_to_wkt) } // namespace common } // namespace oceanbase - +#endif int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); -- GitLab