cmd/ido2icingadb: reason not actually used INNER JOINs

This commit is contained in:
Alexander A. Klimov 2021-10-05 15:19:21 +02:00
parent ae57d4fe6f
commit d9e2c7daf4
2 changed files with 8 additions and 0 deletions

View file

@ -46,6 +46,8 @@ func buildEventTimeCache(ht *historyType, idoColumns []string) {
sliceIdoHistory(
ht.snapshot,
"SELECT "+strings.Join(idoColumns, ", ")+" FROM "+ht.idoTable+
// For actual migration icinga_objects will be joined anyway,
// so it makes no sense to take vanished objects into account.
" xh USE INDEX (PRIMARY) INNER JOIN icinga_objects o ON o.object_id=xh.object_id WHERE xh."+
ht.idoIdColumn+" > ? ORDER BY xh."+ht.idoIdColumn+" LIMIT ?",
nil, checkpoint.MaxId.Int64,
@ -171,6 +173,8 @@ func buildPreviousHardStateCache(ht *historyType, idoColumns []string) {
sliceIdoHistory(
ht.snapshot,
"SELECT "+strings.Join(idoColumns, ", ")+" FROM "+ht.idoTable+
// For actual migration icinga_objects will be joined anyway,
// so it makes no sense to take vanished objects into account.
" xh USE INDEX (PRIMARY) INNER JOIN icinga_objects o ON o.object_id=xh.object_id WHERE xh."+
ht.idoIdColumn+" < ? ORDER BY xh."+ht.idoIdColumn+" DESC LIMIT ?",
nil, checkpoint,

View file

@ -175,6 +175,8 @@ func countIdoHistory() {
types.forEach(func(ht *historyType) {
err := ht.snapshot.Get(
&ht.total,
// For actual migration icinga_objects will be joined anyway,
// so it makes no sense to take vanished objects into account.
"SELECT COUNT(*) FROM "+ht.idoTable+" xh INNER JOIN icinga_objects o ON o.object_id=xh.object_id",
)
if err != nil {
@ -199,6 +201,8 @@ func computeProgress(c *Config, idb *icingadb.DB) {
query := "SELECT xh." +
strings.Join(append(append([]string(nil), ht.idoColumns...), ht.idoIdColumn), ", xh.") + " id FROM " +
// For actual migration icinga_objects will be joined anyway,
// so it makes no sense to take vanished objects into account.
ht.idoTable + " xh USE INDEX (PRIMARY) INNER JOIN icinga_objects o ON o.object_id=xh.object_id WHERE " +
ht.idoIdColumn + " > ? ORDER BY xh." + ht.idoIdColumn + " LIMIT ?"