Skip to content

Commit ca73cab

Browse files
authored
Online DDL: ensure requested_timestamp isn't zero, before initializing table schema (vitessio#12263)
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
1 parent cf41ae7 commit ca73cab

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

go/vt/vttablet/onlineddl/schema.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,12 @@ const (
393393
AND cleanup_timestamp IS NULL
394394
AND completed_timestamp IS NULL
395395
`
396+
sqlFixRequestedTimestamp = `UPDATE _vt.schema_migrations
397+
SET
398+
requested_timestamp = added_timestamp
399+
WHERE
400+
requested_timestamp < added_timestamp;
401+
`
396402
sqlSelectMigration = `SELECT
397403
id,
398404
migration_uuid,
@@ -612,6 +618,13 @@ var (
612618
var ApplyDDL = []string{
613619
sqlCreateSidecarDB,
614620
sqlCreateSchemaMigrationsTable,
621+
// Fixing a historical issue: past values of requested_timestamp could be '0000-00-00 00:00:00'.
622+
// In turn, those cause `ERROR 1292 (22007): Incorrect datetime value` when attempting to
623+
// make any DDL on the table.
624+
// We trust added_timestamp to be non-zero (it defaults CURRENT_TIMESTAMP and never modified),
625+
// and so we set requested_timestamp to that value.
626+
// The query makes a full table scan, because neither column is indexed.
627+
sqlFixRequestedTimestamp, // end of fix
615628
alterSchemaMigrationsTableRetries,
616629
alterSchemaMigrationsTableTablet,
617630
alterSchemaMigrationsTableArtifacts,

0 commit comments

Comments
 (0)