Skip to content

Commit

Permalink
dumpling: skip query tables when use --sql (#45240) (#45266)
Browse files Browse the repository at this point in the history
close #45239
  • Loading branch information
ti-chi-bot committed Jul 10, 2023
1 parent a1ef856 commit ceb40b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dumpling/export/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ func getListTableTypeByConf(conf *Config) listTableType {
}

func prepareTableListToDump(tctx *tcontext.Context, conf *Config, db *sql.Conn) error {
if conf.specifiedTables {
if conf.specifiedTables || conf.SQL != "" {
return nil
}
databases, err := prepareDumpingDatabases(tctx, conf, db)
Expand Down
8 changes: 7 additions & 1 deletion dumpling/tests/no_table_and_db_name/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ assert() {
}

TEST_NAME=no_table_and_db_name
export DUMPLING_TEST_PORT=4000
run_sql "drop database if exists $TEST_NAME"
run_sql "create database $TEST_NAME DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"
export DUMPLING_TEST_DATABASE=no_table_and_db_name
Expand All @@ -22,8 +23,13 @@ chars_20="1111_0000_1111_0000_"
# insert 100 records, each occupies 20 bytes
run_sql "insert into t values $(seq -s, 100 | sed 's/,*$//g' | sed "s/[0-9]*/('$chars_20')/g");"

run_sql "set global tidb_general_log=1;"
# dumping with file size = 233 bytes, actually 10 rows
run_dumpling -F 233B --filetype csv --sql "select * from $TEST_NAME.t"
run_sql "set global tidb_general_log=0;"
assert [ $( grep "GENERAL_LOG" $DUMPLING_TEST_DIR/tidb.log | grep --ignore-case "INFORMATION_SCHEMA.TABLES" | wc -l ) -eq 0 ]
assert [ $( grep "GENERAL_LOG" $DUMPLING_TEST_DIR/tidb.log | grep --ignore-case "SHOW FULL TABLES" | wc -l ) -eq 0 ]
assert [ $( grep "GENERAL_LOG" $DUMPLING_TEST_DIR/tidb.log | grep --ignore-case "SHOW TABLE STATUS" | wc -l ) -eq 0 ]

assert [ $( ls -lh $DUMPLING_OUTPUT_DIR | grep -e ".csv$" | wc -l ) -eq 10 ]

Expand All @@ -39,4 +45,4 @@ assert [ $( cat $DUMPLING_OUTPUT_DIR/*.csv | wc -l ) -eq $(( 100 + 10 )) ]
# 10 files with header.
# assert [ $( cat $DUMPLING_OUTPUT_DIR/*.sql | wc -l ) -eq $(( 100 + 10 * 2 )) ]

echo "TEST: [$TEST_NAME] passed."
echo "TEST: [$TEST_NAME] passed."

0 comments on commit ceb40b3

Please sign in to comment.