diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/NereidsPlanner.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/NereidsPlanner.java index a7bc9dfb18..89a9d220be 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/NereidsPlanner.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/NereidsPlanner.java @@ -253,8 +253,12 @@ public class NereidsPlanner extends Planner { // print memo before choose plan. // if chooseNthPlan failed, we could get memo to debug if (cascadesContext.getConnectContext().getSessionVariable().dumpNereidsMemo) { - String memo = cascadesContext.getMemo().toString(); - LOG.info("{}\n{}", ConnectContext.get().getQueryIdentifier(), memo); + Memo memo = cascadesContext.getMemo(); + if (memo != null) { + LOG.info("{}\n{}", ConnectContext.get().getQueryIdentifier(), memo.toString()); + } else { + LOG.info("{}\nMemo is null", ConnectContext.get().getQueryIdentifier()); + } } int nth = cascadesContext.getConnectContext().getSessionVariable().getNthOptimizedPlan(); @@ -583,10 +587,15 @@ public class NereidsPlanner extends Planner { plan = optimizedPlan.shape(""); break; case MEMO_PLAN: - plan = cascadesContext.getMemo().toString() + Memo memo = cascadesContext.getMemo(); + if (memo == null) { + plan = "Memo is null"; + } else { + plan = memo.toString() + "\n\n========== OPTIMIZED PLAN ==========\n" + optimizedPlan.treeString() + mvSummary; + } break; case ALL_PLAN: plan = "========== PARSED PLAN " diff --git a/regression-test/data/correctness/test_insert_table_with_dump_nereids_memo.out b/regression-test/data/correctness/test_insert_table_with_dump_nereids_memo.out new file mode 100644 index 0000000000..a8291e7538 --- /dev/null +++ b/regression-test/data/correctness/test_insert_table_with_dump_nereids_memo.out @@ -0,0 +1,5 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select -- +1 hello +2 world + diff --git a/regression-test/suites/correctness/test_insert_table_with_dump_nereids_memo.groovy b/regression-test/suites/correctness/test_insert_table_with_dump_nereids_memo.groovy new file mode 100644 index 0000000000..a51aba93a5 --- /dev/null +++ b/regression-test/suites/correctness/test_insert_table_with_dump_nereids_memo.groovy @@ -0,0 +1,58 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite("test_insert_table_with_dump_nereids_memo") { + + def testTable = "test_insert_table_with_dump_nereids_memo" + // Clean up any existing table with the same name + sql "DROP TABLE IF EXISTS ${testTable}" + + // Create table with with test 'dump_nereids_memo' SessionVariable + // set dump_nereids_memo to true + sql "set dump_nereids_memo = true" + + // Verify that the variable is set correctly + def result = sql "SHOW VARIABLES LIKE 'dump_nereids_memo'" + assertTrue(result[0][1] == "true") + + sql """ + CREATE TABLE ${testTable} + ( + id int, + name string + ) + COMMENT "test table with dump_nereids_memo" + DISTRIBUTED BY HASH(id) BUCKETS 1 + PROPERTIES ( + "replication_num" = "1" + ) + """ + + // Insert data into the table + sql "INSERT INTO ${testTable} VALUES (1, 'hello'), (2, 'world')" + + // Synchronize to ensure data is visible + sql "SYNC" + + // Verify that data was inserted correctly + qt_select "SELECT * FROM ${testTable} ORDER BY id" + + // Clean up after the test + sql "DROP TABLE IF EXISTS ${testTable}" + sql "set dump_nereids_memo = false" + +} \ No newline at end of file