cleanup
This commit is contained in:
parent
1e1e42d1f1
commit
dae048231d
|
@ -393,7 +393,9 @@ func (this *Applier) WriteChangelog(hint, value string) (string, error) {
|
|||
explicitId = 3
|
||||
}
|
||||
query := fmt.Sprintf(`
|
||||
insert /* gh-ost */ into %s.%s
|
||||
insert /* gh-ost */
|
||||
into
|
||||
%s.%s
|
||||
(id, hint, value)
|
||||
values
|
||||
(NULLIF(?, 0), ?, ?)
|
||||
|
@ -868,7 +870,8 @@ func (this *Applier) ExpectProcess(sessionId int64, stateHint, infoHint string)
|
|||
found := false
|
||||
query := `
|
||||
select /* gh-ost */ id
|
||||
from information_schema.processlist
|
||||
from
|
||||
information_schema.processlist
|
||||
where
|
||||
id != connection_id()
|
||||
and ? in (0, id)
|
||||
|
|
|
@ -444,11 +444,14 @@ func (this *Inspector) validateTableForeignKeys(allowChildForeignKeys bool) erro
|
|||
SELECT /* gh-ost */
|
||||
SUM(REFERENCED_TABLE_NAME IS NOT NULL AND TABLE_SCHEMA=? AND TABLE_NAME=?) as num_child_side_fk,
|
||||
SUM(REFERENCED_TABLE_NAME IS NOT NULL AND REFERENCED_TABLE_SCHEMA=? AND REFERENCED_TABLE_NAME=?) as num_parent_side_fk
|
||||
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
|
||||
FROM
|
||||
INFORMATION_SCHEMA.KEY_COLUMN_USAGE
|
||||
WHERE
|
||||
REFERENCED_TABLE_NAME IS NOT NULL
|
||||
AND ((TABLE_SCHEMA=? AND TABLE_NAME=?)
|
||||
OR (REFERENCED_TABLE_SCHEMA=? AND REFERENCED_TABLE_NAME=?)
|
||||
AND (
|
||||
(TABLE_SCHEMA=? AND TABLE_NAME=?)
|
||||
OR
|
||||
(REFERENCED_TABLE_SCHEMA=? AND REFERENCED_TABLE_NAME=?)
|
||||
)`
|
||||
numParentForeignKeys := 0
|
||||
numChildForeignKeys := 0
|
||||
|
@ -487,7 +490,8 @@ func (this *Inspector) validateTableForeignKeys(allowChildForeignKeys bool) erro
|
|||
func (this *Inspector) validateTableTriggers() error {
|
||||
query := `
|
||||
SELECT /* gh-ost */ COUNT(*) AS num_triggers
|
||||
FROM INFORMATION_SCHEMA.TRIGGERS
|
||||
FROM
|
||||
INFORMATION_SCHEMA.TRIGGERS
|
||||
WHERE
|
||||
TRIGGER_SCHEMA=?
|
||||
AND EVENT_OBJECT_TABLE=?`
|
||||
|
@ -629,9 +633,9 @@ func (this *Inspector) applyColumnTypes(databaseName, tableName string, columnsL
|
|||
// getAutoIncrementValue get's the original table's AUTO_INCREMENT value, if exists (0 value if not exists)
|
||||
func (this *Inspector) getAutoIncrementValue(tableName string) (autoIncrement uint64, err error) {
|
||||
query := `
|
||||
SELECT /* gh-ost */
|
||||
AUTO_INCREMENT
|
||||
FROM INFORMATION_SCHEMA.TABLES
|
||||
SELECT /* gh-ost */ AUTO_INCREMENT
|
||||
FROM
|
||||
INFORMATION_SCHEMA.TABLES
|
||||
WHERE
|
||||
TABLES.TABLE_SCHEMA = ?
|
||||
AND TABLES.TABLE_NAME = ?
|
||||
|
@ -647,61 +651,63 @@ func (this *Inspector) getAutoIncrementValue(tableName string) (autoIncrement ui
|
|||
// candidate for chunking
|
||||
func (this *Inspector) getCandidateUniqueKeys(tableName string) (uniqueKeys [](*sql.UniqueKey), err error) {
|
||||
query := `
|
||||
SELECT /* gh-ost */
|
||||
COLUMNS.TABLE_SCHEMA,
|
||||
COLUMNS.TABLE_NAME,
|
||||
COLUMNS.COLUMN_NAME,
|
||||
UNIQUES.INDEX_NAME,
|
||||
UNIQUES.COLUMN_NAMES,
|
||||
UNIQUES.COUNT_COLUMN_IN_INDEX,
|
||||
COLUMNS.DATA_TYPE,
|
||||
COLUMNS.CHARACTER_SET_NAME,
|
||||
LOCATE('auto_increment', EXTRA) > 0 as is_auto_increment,
|
||||
has_nullable
|
||||
FROM INFORMATION_SCHEMA.COLUMNS INNER JOIN (
|
||||
SELECT
|
||||
TABLE_SCHEMA,
|
||||
TABLE_NAME,
|
||||
INDEX_NAME,
|
||||
COUNT(*) AS COUNT_COLUMN_IN_INDEX,
|
||||
GROUP_CONCAT(COLUMN_NAME ORDER BY SEQ_IN_INDEX ASC) AS COLUMN_NAMES,
|
||||
SUBSTRING_INDEX(GROUP_CONCAT(COLUMN_NAME ORDER BY SEQ_IN_INDEX ASC), ',', 1) AS FIRST_COLUMN_NAME,
|
||||
SUM(NULLABLE='YES') > 0 AS has_nullable
|
||||
FROM INFORMATION_SCHEMA.STATISTICS
|
||||
SELECT /* gh-ost */
|
||||
COLUMNS.TABLE_SCHEMA,
|
||||
COLUMNS.TABLE_NAME,
|
||||
COLUMNS.COLUMN_NAME,
|
||||
UNIQUES.INDEX_NAME,
|
||||
UNIQUES.COLUMN_NAMES,
|
||||
UNIQUES.COUNT_COLUMN_IN_INDEX,
|
||||
COLUMNS.DATA_TYPE,
|
||||
COLUMNS.CHARACTER_SET_NAME,
|
||||
LOCATE('auto_increment', EXTRA) > 0 as is_auto_increment,
|
||||
has_nullable
|
||||
FROM
|
||||
INFORMATION_SCHEMA.COLUMNS
|
||||
INNER JOIN (
|
||||
SELECT
|
||||
TABLE_SCHEMA,
|
||||
TABLE_NAME,
|
||||
INDEX_NAME,
|
||||
COUNT(*) AS COUNT_COLUMN_IN_INDEX,
|
||||
GROUP_CONCAT(COLUMN_NAME ORDER BY SEQ_IN_INDEX ASC) AS COLUMN_NAMES,
|
||||
SUBSTRING_INDEX(GROUP_CONCAT(COLUMN_NAME ORDER BY SEQ_IN_INDEX ASC), ',', 1) AS FIRST_COLUMN_NAME,
|
||||
SUM(NULLABLE='YES') > 0 AS has_nullable
|
||||
FROM INFORMATION_SCHEMA.STATISTICS
|
||||
WHERE
|
||||
NON_UNIQUE=0
|
||||
AND TABLE_SCHEMA = ?
|
||||
AND TABLE_NAME = ?
|
||||
GROUP BY TABLE_SCHEMA, TABLE_NAME, INDEX_NAME
|
||||
) AS UNIQUES
|
||||
ON (
|
||||
COLUMNS.COLUMN_NAME = UNIQUES.FIRST_COLUMN_NAME
|
||||
)
|
||||
WHERE
|
||||
NON_UNIQUE=0
|
||||
AND TABLE_SCHEMA = ?
|
||||
AND TABLE_NAME = ?
|
||||
GROUP BY TABLE_SCHEMA, TABLE_NAME, INDEX_NAME
|
||||
) AS UNIQUES
|
||||
ON (
|
||||
COLUMNS.COLUMN_NAME = UNIQUES.FIRST_COLUMN_NAME
|
||||
)
|
||||
WHERE
|
||||
COLUMNS.TABLE_SCHEMA = ?
|
||||
AND COLUMNS.TABLE_NAME = ?
|
||||
ORDER BY
|
||||
COLUMNS.TABLE_SCHEMA, COLUMNS.TABLE_NAME,
|
||||
CASE UNIQUES.INDEX_NAME
|
||||
WHEN 'PRIMARY' THEN 0
|
||||
ELSE 1
|
||||
END,
|
||||
CASE has_nullable
|
||||
WHEN 0 THEN 0
|
||||
ELSE 1
|
||||
END,
|
||||
CASE IFNULL(CHARACTER_SET_NAME, '')
|
||||
WHEN '' THEN 0
|
||||
ELSE 1
|
||||
END,
|
||||
CASE DATA_TYPE
|
||||
WHEN 'tinyint' THEN 0
|
||||
WHEN 'smallint' THEN 1
|
||||
WHEN 'int' THEN 2
|
||||
WHEN 'bigint' THEN 3
|
||||
ELSE 100
|
||||
END,
|
||||
COUNT_COLUMN_IN_INDEX`
|
||||
COLUMNS.TABLE_SCHEMA = ?
|
||||
AND COLUMNS.TABLE_NAME = ?
|
||||
ORDER BY
|
||||
COLUMNS.TABLE_SCHEMA, COLUMNS.TABLE_NAME,
|
||||
CASE UNIQUES.INDEX_NAME
|
||||
WHEN 'PRIMARY' THEN 0
|
||||
ELSE 1
|
||||
END,
|
||||
CASE has_nullable
|
||||
WHEN 0 THEN 0
|
||||
ELSE 1
|
||||
END,
|
||||
CASE IFNULL(CHARACTER_SET_NAME, '')
|
||||
WHEN '' THEN 0
|
||||
ELSE 1
|
||||
END,
|
||||
CASE DATA_TYPE
|
||||
WHEN 'tinyint' THEN 0
|
||||
WHEN 'smallint' THEN 1
|
||||
WHEN 'int' THEN 2
|
||||
WHEN 'bigint' THEN 3
|
||||
ELSE 100
|
||||
END,
|
||||
COUNT_COLUMN_IN_INDEX`
|
||||
err = sqlutils.QueryRowsMap(this.db, query, func(m sqlutils.RowMap) error {
|
||||
uniqueKey := &sql.UniqueKey{
|
||||
Name: m.GetString("INDEX_NAME"),
|
||||
|
@ -791,7 +797,9 @@ func (this *Inspector) showCreateTable(tableName string) (createTableStatement s
|
|||
// readChangelogState reads changelog hints
|
||||
func (this *Inspector) readChangelogState(hint string) (string, error) {
|
||||
query := fmt.Sprintf(`
|
||||
select /* gh-ost */ hint, value from %s.%s
|
||||
select /* gh-ost */ hint, value
|
||||
from
|
||||
%s.%s
|
||||
where
|
||||
hint = ? and id <= 255`,
|
||||
sql.EscapeName(this.migrationContext.DatabaseName),
|
||||
|
|
|
@ -222,7 +222,11 @@ func BuildRangeInsertQuery(databaseName, originalTableName, ghostTableName strin
|
|||
transactionalClause = "lock in share mode"
|
||||
}
|
||||
result = fmt.Sprintf(`
|
||||
insert /* gh-ost %s.%s */ ignore into %s.%s (%s) (
|
||||
insert /* gh-ost %s.%s */ ignore
|
||||
into
|
||||
%s.%s
|
||||
(%s)
|
||||
(
|
||||
select %s from %s.%s
|
||||
force index (%s)
|
||||
where (%s and %s) %s
|
||||
|
@ -330,7 +334,8 @@ func BuildUniqueKeyRangeEndPreparedQueryViaTemptable(databaseName, tableName str
|
|||
}
|
||||
}
|
||||
result = fmt.Sprintf(`
|
||||
select /* gh-ost %s.%s %s */ %s from (
|
||||
select /* gh-ost %s.%s %s */ %s
|
||||
from (
|
||||
select
|
||||
%s
|
||||
from
|
||||
|
@ -377,7 +382,8 @@ func buildUniqueKeyMinMaxValuesPreparedQuery(databaseName, tableName string, uni
|
|||
}
|
||||
}
|
||||
query := fmt.Sprintf(`
|
||||
select /* gh-ost %s.%s */ %s from
|
||||
select /* gh-ost %s.%s */ %s
|
||||
from
|
||||
%s.%s
|
||||
order by
|
||||
%s
|
||||
|
@ -408,7 +414,8 @@ func BuildDMLDeleteQuery(databaseName, tableName string, tableColumns, uniqueKey
|
|||
return result, uniqueKeyArgs, err
|
||||
}
|
||||
result = fmt.Sprintf(`
|
||||
delete /* gh-ost %s.%s */ from
|
||||
delete /* gh-ost %s.%s */
|
||||
from
|
||||
%s.%s
|
||||
where
|
||||
%s`,
|
||||
|
@ -445,7 +452,8 @@ func BuildDMLInsertQuery(databaseName, tableName string, tableColumns, sharedCol
|
|||
preparedValues := buildColumnsPreparedValues(mappedSharedColumns)
|
||||
|
||||
result = fmt.Sprintf(`
|
||||
replace /* gh-ost %s.%s */ into
|
||||
replace /* gh-ost %s.%s */
|
||||
into
|
||||
%s.%s
|
||||
(%s)
|
||||
values
|
||||
|
|
Loading…
Reference in New Issue
Block a user