Skip to content
This repository has been archived by the owner on Aug 21, 2023. It is now read-only.

fix unique key null bug #119

Merged
merged 2 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions tests/null_unique_index/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh

set -eu
cur=$(cd `dirname $0`; pwd)

DB_NAME="null_unique_key"

# drop database on mysql
run_sql "drop database if exists \`$DB_NAME\`;"

# build data on mysql
run_sql "create database \`$DB_NAME\`;"
run_sql "create table \`$DB_NAME\`.\`t\` (a int unique key, b int);"
run_sql "insert into \`$DB_NAME\`.\`t\` values (1, 2), (NULL, 1);"


# dumping
export DUMPLING_TEST_DATABASE=$DB_NAME
run_dumpling -r 1

data="NULL"
cnt=$(sed "s/$data/$data\n/g" $DUMPLING_OUTPUT_DIR/$DB_NAME.t.1.sql | grep -c "$data") || true
[ $cnt = 1 ]

6 changes: 5 additions & 1 deletion v4/export/ir_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,16 +323,20 @@ func splitTableDataIntoChunks(
}

chunkIndex := 0
nullValueCondition := fmt.Sprintf("`%s` IS NULL OR ", escapeString(field))
LOOP:
for cutoff <= max {
chunkIndex += 1
where := fmt.Sprintf("(`%s` >= %d AND `%s` < %d)", escapeString(field), cutoff, escapeString(field), cutoff+estimatedStep)
where := fmt.Sprintf("%s(`%s` >= %d AND `%s` < %d)", nullValueCondition, escapeString(field), cutoff, escapeString(field), cutoff+estimatedStep)
query = buildSelectQuery(dbName, tableName, selectedField, buildWhereCondition(conf, where), orderByClause)
rows, err := db.Query(query)
if err != nil {
errCh <- errors.WithMessage(err, query)
return
}
if len(nullValueCondition) > 0 {
nullValueCondition = ""
}

td := &tableData{
database: dbName,
Expand Down