Skip to content

Commit 8373610

Browse files
authored
[opt](ctas) add a variable to control varchar length in ctas (#37069) (#37284)
pick from master #37069 add a new session variable: use_max_length_of_varchar_in_ctas In CTAS (Create Table As Select), if CHAR/VARCHAR columns do not originate from the source table, whether to set the length of such a column to MAX, which is 65533. The default is true.
1 parent 4e4f3d2 commit 8373610

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateTableCommand.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,12 @@ public void run(ConnectContext ctx, StmtExecutor executor) throws Exception {
143143
}
144144
}
145145
} else {
146-
dataType = TypeCoercionUtils.replaceSpecifiedType(dataType,
147-
VarcharType.class, VarcharType.MAX_VARCHAR_TYPE);
148-
dataType = TypeCoercionUtils.replaceSpecifiedType(dataType,
149-
CharType.class, VarcharType.MAX_VARCHAR_TYPE);
146+
if (ctx.getSessionVariable().useMaxLengthOfVarcharInCtas) {
147+
dataType = TypeCoercionUtils.replaceSpecifiedType(dataType,
148+
VarcharType.class, VarcharType.MAX_VARCHAR_TYPE);
149+
dataType = TypeCoercionUtils.replaceSpecifiedType(dataType,
150+
CharType.class, VarcharType.MAX_VARCHAR_TYPE);
151+
}
150152
}
151153
}
152154
// if the column is an expression, we set it to nullable, otherwise according to the nullable of the slot.

fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,8 @@ public class SessionVariable implements Serializable, Writable {
572572

573573
public static final String MAX_COLUMN_READER_NUM = "max_column_reader_num";
574574

575+
public static final String USE_MAX_LENGTH_OF_VARCHAR_IN_CTAS = "use_max_length_of_varchar_in_ctas";
576+
575577
public static final List<String> DEBUG_VARIABLES = ImmutableList.of(
576578
SKIP_DELETE_PREDICATE,
577579
SKIP_DELETE_BITMAP,
@@ -1902,6 +1904,13 @@ public void setIgnoreShapePlanNodes(String ignoreShapePlanNodes) {
19021904
checker = "checkExternalAggPartitionBits", fuzzy = true)
19031905
public int externalAggPartitionBits = 5; // means that the hash table will be partitioned into 32 blocks.
19041906

1907+
@VariableMgr.VarAttr(name = USE_MAX_LENGTH_OF_VARCHAR_IN_CTAS, description = {
1908+
"在CTAS中,如果 CHAR / VARCHAR 列不来自于源表,是否是将这一列的长度设置为 MAX,即65533。默认为 true。",
1909+
"In CTAS (Create Table As Select), if CHAR/VARCHAR columns do not originate from the source table,"
1910+
+ " whether to set the length of such a column to MAX, which is 65533. The default is true."
1911+
})
1912+
public boolean useMaxLengthOfVarcharInCtas = true;
1913+
19051914
public boolean isEnableJoinSpill() {
19061915
return enableJoinSpill;
19071916
}

regression-test/data/nereids_p0/create_table/test_ctas.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ r2 {"title":"Amount","value":2.1}
2121
2.1 2.20000 2.3 2.400000 2.500000 2.600000
2222
2.1 2.20000 2.3 2.400000 2.500000 2.600000
2323

24+
-- !desc --
25+
__substring_0 VARCHAR(30) Yes true \N
26+

regression-test/suites/nereids_p0/create_table/test_ctas.groovy

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
// under the License.
1717

1818
suite("nereids_test_ctas") {
19-
sql 'set enable_nereids_planner=true'
20-
sql 'set enable_fallback_to_original_planner=false'
21-
sql 'set enable_nereids_dml=true'
22-
2319
sql """ DROP TABLE IF EXISTS test_ctas """
2420
sql """ DROP TABLE IF EXISTS test_ctas1 """
2521
sql """ DROP TABLE IF EXISTS test_ctas2 """
@@ -271,5 +267,13 @@ suite("nereids_test_ctas") {
271267
sql 'drop table c'
272268
sql 'drop table test_date_v2'
273269
}
270+
271+
sql """DROP TABLE IF EXISTS test_varchar_length"""
272+
sql """set use_max_length_of_varchar_in_ctas = false"""
273+
sql """CREATE TABLE test_varchar_length properties ("replication_num"="1") AS SELECT CAST("1" AS VARCHAR(30))"""
274+
qt_desc """desc test_varchar_length"""
275+
sql """DROP TABLE IF EXISTS test_varchar_length"""
276+
sql """set use_max_length_of_varchar_in_ctas = true"""
277+
274278
}
275279

0 commit comments

Comments
 (0)