diff --git a/deps/oblib/src/lib/xml/ob_xpath.cpp b/deps/oblib/src/lib/xml/ob_xpath.cpp index 9f75a8aa68..a6ce46427c 100644 --- a/deps/oblib/src/lib/xml/ob_xpath.cpp +++ b/deps/oblib/src/lib/xml/ob_xpath.cpp @@ -2825,6 +2825,9 @@ int ObPathFilterOpNode::init_right_without_filter(ObPathCtx &ctx, ObSeekResult& { INIT_SUCC(ret); bool get_valid_right = false; + if (OB_NOT_NULL(right_)) { + right_->is_seeked_ = false; + } while (OB_SUCC(ret) && !get_valid_right) { ObSeekResult left_res; if (OB_FAIL(get_valid_res(ctx, left_res, true))) { @@ -2949,7 +2952,8 @@ int ObPathFilterOpNode::eval_node(ObPathCtx &ctx, ObSeekResult& res) } } - if (OB_SUCC(ret)) { // do nothing + if (OB_SUCC(ret)) { + is_seeked_ = true; } else if (ret == OB_ITER_END) { is_seeked_ = false; // reset left_->is_seeked_ = false; diff --git a/src/sql/das/ob_das_dml_ctx_define.cpp b/src/sql/das/ob_das_dml_ctx_define.cpp index 1b8c29d129..be7c4a8999 100644 --- a/src/sql/das/ob_das_dml_ctx_define.cpp +++ b/src/sql/das/ob_das_dml_ctx_define.cpp @@ -156,7 +156,7 @@ int ObDASDMLIterator::get_next_spatial_index_row(ObNewRow *&row) ret = OB_ERR_UNEXPECTED; LOG_WARN("invalid index for sr", K(ret), KPC(sr), K(i), K(main_ctdef_->old_row_projector_)); } else { - geo_idx = i; + geo_idx = projector_idx; geo_wkb = sr->cells()[projector_idx].get_string(); geo_meta = main_ctdef_->column_types_.at(i); } diff --git a/src/sql/engine/expr/ob_expr_priv_st_asmvtgeom.cpp b/src/sql/engine/expr/ob_expr_priv_st_asmvtgeom.cpp index 351961e7d9..29004578a6 100644 --- a/src/sql/engine/expr/ob_expr_priv_st_asmvtgeom.cpp +++ b/src/sql/engine/expr/ob_expr_priv_st_asmvtgeom.cpp @@ -47,7 +47,7 @@ int ObExprPrivSTAsMVTGeom::calc_result_typeN(ObExprResType &type, ObExprResType ret = OB_ERR_GIS_INVALID_DATA; LOG_USER_ERROR(OB_ERR_GIS_INVALID_DATA, N_PRIV_ST_ASMVTGEOM); LOG_WARN("invalid type", K(ret), K(obj_type1)); - } else if (ObHexStringType != obj_type1 && !ob_is_geometry(obj_type2)) { + } else if (ObHexStringType != obj_type2 && !ob_is_geometry(obj_type2)) { if (ob_is_null(obj_type2)) { ret = OB_ERR_NULL_INPUT; LOG_WARN("_ST_AsMVTGeom: Geometric bounds cannot be null", K(ret), K(obj_type2)); diff --git a/src/sql/engine/expr/ob_expr_xml_func_helper.cpp b/src/sql/engine/expr/ob_expr_xml_func_helper.cpp index eea19da2d6..2cde354344 100644 --- a/src/sql/engine/expr/ob_expr_xml_func_helper.cpp +++ b/src/sql/engine/expr/ob_expr_xml_func_helper.cpp @@ -1243,7 +1243,8 @@ int ObXMLExprHelper::process_sql_udt_results(common::ObObj& value, } } } else if (value.is_geometry()) { - if (is_ps_protocol) { + if (lib::is_mysql_mode()) { + } else if (is_ps_protocol) { #ifdef OB_BUILD_ORACLE_PL ObObj result; if (OB_ISNULL(exec_context)) { diff --git a/src/sql/resolver/ddl/ob_alter_table_resolver.cpp b/src/sql/resolver/ddl/ob_alter_table_resolver.cpp index 8af7393023..318a89309e 100644 --- a/src/sql/resolver/ddl/ob_alter_table_resolver.cpp +++ b/src/sql/resolver/ddl/ob_alter_table_resolver.cpp @@ -5395,22 +5395,8 @@ int ObAlterTableResolver::resolve_change_column(const ParseNode &node) && alter_column_schema.is_set_nullable_) { ret = OB_ERR_PRIMARY_CANT_HAVE_NULL; LOG_WARN("can't set primary key nullable", K(ret)); - } else if (ObGeometryType == origin_col_schema->get_data_type() - && ObGeometryType == alter_column_schema.get_data_type() - && alter_column_schema.get_geo_type() != common::ObGeoType::GEOMETRY - && origin_col_schema->get_geo_type() != common::ObGeoType::GEOMETRY - && origin_col_schema->get_geo_type() != alter_column_schema.get_geo_type()) { - ret = OB_ERR_CANT_CREATE_GEOMETRY_OBJECT; - LOG_USER_ERROR(OB_ERR_CANT_CREATE_GEOMETRY_OBJECT); - LOG_WARN("can't not change geometry type", K(ret), K(origin_col_schema->get_geo_type()), - K(alter_column_schema.get_geo_type())); - } else if (ObGeometryType == origin_col_schema->get_data_type() - && ObGeometryType == alter_column_schema.get_data_type() - && origin_col_schema->get_srid() != alter_column_schema.get_srid()) { - ret = OB_NOT_SUPPORTED; - LOG_USER_ERROR(OB_NOT_SUPPORTED, "not support alter srid"); - LOG_WARN("not support alter srid now", K(ret), - K(origin_col_schema->get_srid()), K(alter_column_schema.get_srid())); + } else if (OB_FAIL(check_alter_geo_column_allowed(alter_column_schema, *origin_col_schema))) { + LOG_WARN("modify geo column not allowed", K(ret)); } } if (OB_SUCC(ret)) { @@ -5534,6 +5520,37 @@ int ObAlterTableResolver::check_modify_column_allowed( return ret; } + +int ObAlterTableResolver::check_alter_geo_column_allowed(const share::schema::AlterColumnSchema &alter_column_schema, + const share::schema::ObColumnSchemaV2 &origin_col_schema) +{ + int ret = OB_SUCCESS; + if (ObGeometryType != origin_col_schema.get_data_type()) { + // do nothing + } else if (origin_col_schema.is_spatial_index_column() + && ObGeometryType != alter_column_schema.get_data_type()) { + ret = OB_ERR_SPATIAL_MUST_HAVE_GEOM_COL; + LOG_USER_ERROR(OB_ERR_SPATIAL_MUST_HAVE_GEOM_COL); + LOG_WARN("can't not alter geometry col with spatial index", K(ret), K(origin_col_schema.get_geo_type()), + K(alter_column_schema.get_geo_type())); + } else if (ObGeometryType == alter_column_schema.get_data_type() + && alter_column_schema.get_geo_type() != common::ObGeoType::GEOMETRY + && origin_col_schema.get_geo_type() != common::ObGeoType::GEOMETRY + && origin_col_schema.get_geo_type() != alter_column_schema.get_geo_type()) { + ret = OB_ERR_CANT_CREATE_GEOMETRY_OBJECT; + LOG_USER_ERROR(OB_ERR_CANT_CREATE_GEOMETRY_OBJECT); + LOG_WARN("can't not alter geometry type", K(ret), K(origin_col_schema.get_geo_type()), + K(alter_column_schema.get_geo_type())); + } else if (ObGeometryType == alter_column_schema.get_data_type() + && origin_col_schema.get_srid() != alter_column_schema.get_srid()) { + ret = OB_NOT_SUPPORTED; + LOG_USER_ERROR(OB_NOT_SUPPORTED, "alter geometry srid"); + LOG_WARN("can't not alter geometry srid", K(ret), + K(origin_col_schema.get_srid()), K(alter_column_schema.get_srid())); + } + return ret; +} + int ObAlterTableResolver::resolve_modify_column(const ParseNode &node, bool &is_modify_column_visibility, ObReducedVisibleColSet &reduced_visible_col_set) @@ -5681,22 +5698,8 @@ int ObAlterTableResolver::resolve_modify_column(const ParseNode &node, && alter_column_schema.is_set_nullable_) { ret = OB_ERR_PRIMARY_CANT_HAVE_NULL; LOG_WARN("can't set primary key nullable", K(ret)); - } else if (ObGeometryType == origin_col_schema->get_data_type() - && ObGeometryType == alter_column_schema.get_data_type() - && alter_column_schema.get_geo_type() != common::ObGeoType::GEOMETRY - && origin_col_schema->get_geo_type() != common::ObGeoType::GEOMETRY - && origin_col_schema->get_geo_type() != alter_column_schema.get_geo_type()) { - ret = OB_ERR_CANT_CREATE_GEOMETRY_OBJECT; - LOG_USER_ERROR(OB_ERR_CANT_CREATE_GEOMETRY_OBJECT); - LOG_WARN("can't not modify geometry type", K(ret), K(origin_col_schema->get_geo_type()), - K(alter_column_schema.get_geo_type())); - } else if (ObGeometryType == origin_col_schema->get_data_type() - && ObGeometryType == alter_column_schema.get_data_type() - && origin_col_schema->get_srid() != alter_column_schema.get_srid()) { - ret = OB_NOT_SUPPORTED; - LOG_USER_ERROR(OB_NOT_SUPPORTED, "Modify geometry srid"); - LOG_WARN("can't not modify geometry srid", K(ret), - K(origin_col_schema->get_srid()), K(alter_column_schema.get_srid())); + } else if (OB_FAIL(check_alter_geo_column_allowed(alter_column_schema, *origin_col_schema))) { + LOG_WARN("modify geo column not allowed", K(ret)); } } } diff --git a/src/sql/resolver/ddl/ob_alter_table_resolver.h b/src/sql/resolver/ddl/ob_alter_table_resolver.h index 3968de15f8..99ef446b1c 100644 --- a/src/sql/resolver/ddl/ob_alter_table_resolver.h +++ b/src/sql/resolver/ddl/ob_alter_table_resolver.h @@ -68,6 +68,8 @@ public: int check_modify_column_allowed(const share::schema::AlterColumnSchema &alter_column_schema, const share::schema::ObColumnSchemaV2 &origin_col_schema, const ObColumnResolveStat &stat); + int check_alter_geo_column_allowed(const share::schema::AlterColumnSchema &alter_column_schema, + const share::schema::ObColumnSchemaV2 &origin_col_schema); int resolve_modify_column(const ParseNode &node, bool &is_modify_column_visibility, ObReducedVisibleColSet &reduced_visible_col_set); diff --git a/src/sql/resolver/ddl/ob_ddl_resolver.cpp b/src/sql/resolver/ddl/ob_ddl_resolver.cpp index ab45ac3090..ca9f711c2d 100644 --- a/src/sql/resolver/ddl/ob_ddl_resolver.cpp +++ b/src/sql/resolver/ddl/ob_ddl_resolver.cpp @@ -6588,8 +6588,27 @@ int ObDDLResolver::resolve_spatial_index_constraint( //do nothing, check result type of expr on rootserver later } } else { - column_schema = table_schema.get_column_schema(column_name); - if (is_oracle_mode) { + // if create idx by alter table, resolved_cols is not null + // if current col in resolved_cols, means it has been altered, use col schema in alter table schema + if (OB_NOT_NULL(resolved_cols) && resolved_cols->count() > 0) { + bool found = false; + for (int i = 0; i < resolved_cols->count() && !found && OB_SUCC(ret); ++i) { + ObColumnSchemaV2* tmp_col_schema = resolved_cols->at(i); + if (OB_ISNULL(tmp_col_schema)) { + ret = OB_BAD_NULL_ERROR; + LOG_WARN("should not be null.", K(i), K(resolved_cols->count()), K(ret)); + } else { + ObCompareNameWithTenantID column_name_cmp(table_schema.get_tenant_id()); + if (0 == column_name_cmp.compare(column_name, tmp_col_schema->get_column_name_str())) { + found = true; + column_schema = tmp_col_schema; + } + } + } + } + if (OB_FAIL(ret)) { + } else if (OB_ISNULL(column_schema) && OB_FALSE_IT(column_schema = table_schema.get_column_schema(column_name))) { + } else if (is_oracle_mode) { if (OB_NOT_NULL(column_schema) && ob_is_geometry_tc(column_schema->get_data_type())) { ret = OB_NOT_SUPPORTED; LOG_WARN("oracle spatial index not supported", K(ret)); 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 eefd202ffb..4baf465d47 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 @@ -35,11 +35,11 @@ ERROR HY000: The SRID of the geometry does not match the SRID of the column. The # Try to alter the SRID of the columns, which should fail for all columns # now since they already contain data. ALTER TABLE t1 CHANGE COLUMN no_srid no_srid POINT SRID 0 DEFAULT NULL; -ERROR 0A000: not support alter srid not supported +ERROR 0A000: alter geometry srid not supported ALTER TABLE t1 CHANGE COLUMN srid_0 srid_0 POINT SRID 4326 DEFAULT NULL; -ERROR 0A000: not support alter srid not supported +ERROR 0A000: alter geometry srid not supported ALTER TABLE t1 CHANGE COLUMN srid_4326 srid_4326 POINT SRID 0 DEFAULT NULL; -ERROR 0A000: not support alter srid not supported +ERROR 0A000: alter geometry srid not supported # Removing the SRID specification from a column should work just fine. # Setting the SRID to a non-existing SRID should not work. ALTER TABLE t1 CHANGE COLUMN srid_4326 srid_1 POINT SRID 1 DEFAULT NULL; @@ -63,9 +63,9 @@ INSERT INTO t1 VALUES (ST_GeomFromText('POINT(1 1)', 4326)), (ST_GeomFromText('POINT(5 5)', 4326)), (ST_GeomFromText('POINT(6 6)', 0)); ALTER TABLE t1 CHANGE COLUMN col1 col1 POINT SRID 4326; -ERROR 0A000: not support alter srid not supported +ERROR 0A000: alter geometry srid not supported ALTER TABLE t1 CHANGE COLUMN col1 col1 POINT SRID 4326; -ERROR 0A000: not support alter srid not supported +ERROR 0A000: alter geometry srid not supported DROP TABLE t1; # Creating a column with SRID property on a MyISAM table should only # be supported if the SRID represents a cartesian coordinate system. @@ -221,25 +221,25 @@ t1 CREATE TABLE `t1` ( SPATIAL KEY `idx1` (`col1`) BLOCK_SIZE 16384 LOCAL ) DEFAULT CHARSET = utf8mb4 COMPRESSION = 'lz4_1.0' REPLICA_NUM = NUM BLOCK_SIZE = SIZE USE_BLOOM_FILTER = FALSE TABLET_SIZE = SIZE PCTFREE = 10 ALTER TABLE t1 CHANGE COLUMN col1 col1 POINT NOT NULL SRID 0; -ERROR 0A000: not support alter srid not supported +ERROR 0A000: alter geometry srid not supported ALTER TABLE t1 CHANGE COLUMN col1 col1 POINT NOT NULL; -ERROR 0A000: not support alter srid not supported +ERROR 0A000: alter geometry srid not supported ALTER TABLE t1 CHANGE COLUMN col1 col1 POINT NOT NULL SRID 0; -ERROR 0A000: not support alter srid not supported +ERROR 0A000: alter geometry srid not supported ALTER TABLE t1 CHANGE COLUMN col1 col1 POINT NOT NULL; -ERROR 0A000: not support alter srid not supported +ERROR 0A000: alter geometry srid not supported ALTER TABLE t1 CHANGE COLUMN col1 col1 POINT NOT NULL SRID 0; -ERROR 0A000: not support alter srid not supported +ERROR 0A000: alter geometry srid not supported ALTER TABLE t1 CHANGE COLUMN col1 col1 POINT NOT NULL; -ERROR 0A000: not support alter srid not supported +ERROR 0A000: alter geometry srid not supported ALTER TABLE t1 CHANGE COLUMN col1 col1 POINT NOT NULL SRID 0; -ERROR 0A000: not support alter srid not supported +ERROR 0A000: alter geometry srid not supported ALTER TABLE t1 CHANGE COLUMN col1 col1 POINT NOT NULL; -ERROR 0A000: not support alter srid not supported +ERROR 0A000: alter geometry srid not supported ALTER TABLE t1 CHANGE COLUMN col1 col2 POINT NOT NULL SRID 0; -ERROR 0A000: not support alter srid not supported +ERROR 0A000: alter geometry srid not supported ALTER TABLE t1 CHANGE COLUMN col1 col2 POINT NOT NULL; -ERROR 0A000: not support alter srid not supported +ERROR 0A000: alter geometry srid not supported DROP TABLE t1; # # Bug#26594499 WL#8592: CANNOT GET GEOMETRY OBJECT ERROR @@ -401,11 +401,11 @@ ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field alter table test change p p1 MULTIPOINT; ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field. alter table test modify p POINT SRID 0; -ERROR 0A000: Modify geometry srid not supported +ERROR 0A000: alter geometry srid not supported alter table test change p p1 point srid 0; -ERROR 0A000: not support alter srid not supported +ERROR 0A000: alter geometry srid not supported alter table test change p p1 point; -ERROR 0A000: not support alter srid not supported +ERROR 0A000: alter geometry srid not supported alter table test change p p1 point srid 4326; desc test; Field Type Null Key Default Extra @@ -614,3 +614,27 @@ desc geo_t1; Field Type Null Key Default Extra centroid point YES NULL drop table geo_t1; +drop table if exists t1; +CREATE TABLE `t1` ( +`a` int(10) unsigned NOT NULL, +`b` varchar(19) DEFAULT NULL); +ALTER TABLE t1 ADD COLUMN p2 POINT, ADD KEY(p2); +ERROR 42000: All parts of a SPATIAL index must be NOT NULL. +ALTER TABLE t1 ADD COLUMN p2 POINT, ADD KEY(P2); +ERROR 42000: All parts of a SPATIAL index must be NOT NULL. +ALTER TABLE t1 ADD COLUMN p2 int, ADD KEY(p2); +drop table t1; +bugfix: 56020142 +drop table if exists test_wrong_table; +set binlog_row_image='MINIMAL'; +CREATE TABLE `test_wrong_table` ( +`id` int(32) NOT NULL auto_increment, +`the_geom` polygon NOT NULL /*!80003 SRID 4326 */, +PRIMARY KEY (`id`), +SPATIAL KEY `test_wrong_idx` (`the_geom`) BLOCK_SIZE 16384 LOCAL +); +INSERT INTO test_wrong_table (id, the_geom) VALUES (21, st_geomfromtext('POLYGON((40 50,40 70,50 100,70 100,80 80,70 50,40 50))',4326,'axis-order=lat-long')); +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; 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 86675c3453..f8199af829 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 @@ -771,3 +771,32 @@ drop table if exists geo_t1; create table geo_t1 as select ST_Centroid(ST_geomfromtext('POLYGON((121.474243 31.234504, 121.471775 31.233348, 121.470724 31.23155, 121.471603 31.230229, 121.472655 31.230357, 121.475777 31.232045, 121.474243 31.234504))')) centroid ; desc geo_t1; drop table geo_t1; + +# bugfix: 56075340 +--disable_warnings +drop table if exists t1; +CREATE TABLE `t1` ( + `a` int(10) unsigned NOT NULL, + `b` varchar(19) DEFAULT NULL); +--error 1252 +ALTER TABLE t1 ADD COLUMN p2 POINT, ADD KEY(p2); +--error 1252 +ALTER TABLE t1 ADD COLUMN p2 POINT, ADD KEY(P2); +ALTER TABLE t1 ADD COLUMN p2 int, ADD KEY(p2); +drop table t1; + +--echo bugfix: 56020142 +drop table if exists test_wrong_table; +set binlog_row_image='MINIMAL'; +CREATE TABLE `test_wrong_table` ( + `id` int(32) NOT NULL auto_increment, + `the_geom` polygon NOT NULL /*!80003 SRID 4326 */, + PRIMARY KEY (`id`), + SPATIAL KEY `test_wrong_idx` (`the_geom`) BLOCK_SIZE 16384 LOCAL +); + +INSERT INTO test_wrong_table (id, the_geom) VALUES (21, st_geomfromtext('POLYGON((40 50,40 70,50 100,70 100,80 80,70 50,40 50))',4326,'axis-order=lat-long')); +--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