csun5285 commented on code in PR #50907: URL: https://github.com/apache/doris/pull/50907#discussion_r2102060831
########## fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4: ########## @@ -204,6 +204,7 @@ supportedCreateStatement name=identifier properties=propertyClause? #createStoragePolicy | BUILD INDEX name=identifier ON tableName=multipartIdentifier Review Comment: `BUILD INDEX (name=identifier) ON tableName=multipartIdentifier` ########## fe/fe-core/src/main/cup/sql_parser.cup: ########## @@ -2071,6 +2071,10 @@ create_stmt ::= {: RESULT = new AlterTableStmt(tableName, Lists.newArrayList(new BuildIndexClause(tableName, indexName, partitionNames, false))); :} + | KW_BUILD KW_INDEX KW_ON table_name:tableName Review Comment: ` KW_BUILD KW_INDEX (ident:indexName) KW_ON table_name:tableName opt_partition_names:partitionNames` ########## fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java: ########## @@ -2102,20 +2139,26 @@ public int getAsInt() { } } else if (alterClause instanceof BuildIndexClause) { BuildIndexClause buildIndexClause = (BuildIndexClause) alterClause; - IndexDef indexDef = buildIndexClause.getIndexDef(); - Index index = buildIndexClause.getIndex(); - if (Config.isCloudMode() && index.getIndexType() == IndexDef.IndexType.INVERTED) { - throw new DdlException("BUILD INDEX operation failed: No need to do it in cloud mode."); - } + List<IndexDef> indexDefList = buildIndexClause.getIndexDefList(); + List<Index> indexList = buildIndexClause.getIndexList(); + for (int i = 0; i < indexDefList.size(); i++) { + IndexDef indexDef = indexDefList.get(i); + Index index = indexList.get(i); + if (Config.isCloudMode() + && index.getIndexType() == IndexDef.IndexType.INVERTED + && !index.isNonTokenizedInvertedIndex()) { Review Comment: add case for building tokenized index ########## fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java: ########## @@ -1843,6 +1850,20 @@ public List<List<Comparable>> getAllIndexChangeJobInfos() { return indexChangeJobInfos; } + public List<List<Comparable>> getAllIndexChangeJobInfosInCloud() { Review Comment: unused function ########## regression-test/suites/inverted_index_p0/index_format_v2/test_add_build_index_with_format_v2.groovy: ########## @@ -113,31 +146,68 @@ suite("test_add_build_index_with_format_v2", "inverted_index_format_v2"){ String ip = backendId_to_backendIP.get(backend_id) String port = backendId_to_backendHttpPort.get(backend_id) - // cloud mode is directly schema change, local mode is light schema change. // cloud mode is 12, local mode is 6 if (isCloudMode()) { - check_nested_index_file(ip, port, tablet_id, 7, 2, "V2") - qt_sql "SELECT * FROM $tableName WHERE name match 'andy' order by id, name, score;" - return - } else { - check_nested_index_file(ip, port, tablet_id, 7, 0, "V2") - } + check_nested_index_file(ip, port, tablet_id, 2, 0, "V2") + // build index + sql """ + BUILD INDEX idx_name ON ${tableName}; + """ + wait_for_build_index_on_partition_finish(tableName, timeout) + // cloud mode tablets change after index build + def new_tablet_id = wait_for_tablet_change(tablet_id, tableName, timeout) + check_nested_index_file(ip, port, new_tablet_id, 2, 2, "V2") + query = """ SELECT /*+SET_VAR(enable_profile = true, profile_level = 2)*/ * FROM $tableName WHERE name = 'andy' order by id, name, score; """ + profile("sql_select_with_name_index") { + run { + sql "/* sql_select_with_name_index */ ${query}" + sleep(1000) // sleep 1s wait for the profile collection to be completed + } - // build index - sql """ - BUILD INDEX idx_name ON ${tableName}; - """ - wait_for_build_index_on_partition_finish(tableName, timeout) + check { profileString, exception -> + //log.info(profileString) + assertTrue(profileString.contains("RowsInvertedIndexFiltered: 3")) + } + } + // build index + sql """ + BUILD INDEX idx_score ON ${tableName}; + """ + wait_for_build_index_on_partition_finish(tableName, timeout) + def another_new_tablet_id = wait_for_tablet_change(new_tablet_id, tableName, timeout) + check_nested_index_file(ip, port, another_new_tablet_id, 2, 2, "V2") - check_nested_index_file(ip, port, tablet_id, 7, 1, "V2") + query = """ SELECT /*+SET_VAR(enable_profile = true, profile_level = 2)*/ * FROM $tableName WHERE score > 99 order by id, name, score; """ + profile("sql_select_with_score_index") { + run { + sql "/* sql_select_with_score_index */ ${query}" + sleep(1000) // sleep 1s wait for the profile collection to be completed + } - // build index - sql """ - BUILD INDEX idx_score ON ${tableName}; - """ - wait_for_build_index_on_partition_finish(tableName, timeout) + check { profileString, exception -> + //log.info(profileString) + assertTrue(profileString.contains("RowsInvertedIndexFiltered: 3")) + } + } + } else { + // local mode + check_nested_index_file(ip, port, tablet_id, 2, 0, "V2") + // build index + sql """ + BUILD INDEX idx_name ON ${tableName}; + """ + wait_for_build_index_on_partition_finish(tableName, timeout) - check_nested_index_file(ip, port, tablet_id, 7, 2, "V2") + check_nested_index_file(ip, port, tablet_id, 2, 1, "V2") - qt_sql "SELECT * FROM $tableName WHERE name match 'andy' order by id, name, score;" + // build index + sql """ + BUILD INDEX idx_score ON ${tableName}; + """ + wait_for_build_index_on_partition_finish(tableName, timeout) + + check_nested_index_file(ip, port, tablet_id, 2, 2, "V2") Review Comment: test drop index -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org