Skip to content

Commit

Permalink
stores: handle MySQL
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjan committed Feb 19, 2024
1 parent 6a7f8b0 commit a376608
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
7 changes: 5 additions & 2 deletions stores/hostdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1100,8 +1100,11 @@ func (s *SQLStore) addTestHost(hk types.PublicKey) error {
func (s *SQLStore) addCustomTestHost(hk types.PublicKey, na string) error {
s.unappliedHostKeys[hk] = struct{}{}
s.unappliedAnnouncements = append(s.unappliedAnnouncements, []announcement{{
hostKey: publicKey(hk),
announcement: hostdb.Announcement{NetAddress: na},
hostKey: publicKey(hk),
announcement: hostdb.Announcement{
NetAddress: na,
Timestamp: time.Now(),
},
}}...)
s.lastSave = time.Now().Add(s.persistInterval * -2)
return s.applyUpdates(false)
Expand Down
1 change: 1 addition & 0 deletions stores/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,7 @@ func TestSQLMetadataStore(t *testing.T) {
slabs[i].Shards[0].Model = Model{}
slabs[i].Shards[0].Contracts[0].Model = Model{}
slabs[i].Shards[0].Contracts[0].Host.Model = Model{}
slabs[i].Shards[0].Contracts[0].Host.LastAnnouncement = time.Time{}
slabs[i].HealthValidUntil = 0
}
if !reflect.DeepEqual(slab1, expectedObjSlab1) {
Expand Down
34 changes: 25 additions & 9 deletions stores/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,17 @@ func TestConsensusReset(t *testing.T) {
}
}

type queryPlanExplain struct {
type sqliteQueryPlan struct {
ID int `json:"id"`
Parent int `json:"parent"`
NotUsed bool `json:"notused"`
Detail string `json:"detail"`
}

type mysqlQueryPlan struct {
Extra string `json:"extra"`
}

func TestQueryPlan(t *testing.T) {
ss := newTestSQLStore(t, defaultTestSQLStoreConfig)
defer ss.Close()
Expand Down Expand Up @@ -354,14 +358,26 @@ func TestQueryPlan(t *testing.T) {
}

for _, query := range queries {
var explain queryPlanExplain
err := ss.db.Raw(fmt.Sprintf("EXPLAIN QUERY PLAN %s;", query)).Scan(&explain).Error
if err != nil {
t.Fatal(err)
}
if !(strings.Contains(explain.Detail, "USING INDEX") ||
strings.Contains(explain.Detail, "USING COVERING INDEX")) {
t.Fatalf("query '%s' should use an index, instead the plan was '%s'", query, explain.Detail)
if isSQLite(ss.db) {
var explain sqliteQueryPlan
err := ss.db.Raw(fmt.Sprintf("EXPLAIN QUERY PLAN %s;", query)).Scan(&explain).Error
if err != nil {
t.Fatal(err)
}
if !(strings.Contains(explain.Detail, "USING INDEX") ||
strings.Contains(explain.Detail, "USING COVERING INDEX")) {
t.Fatalf("query '%s' should use an index, instead the plan was '%s'", query, explain.Detail)
}
} else {
var explain mysqlQueryPlan
err := ss.db.Raw(fmt.Sprintf("EXPLAIN QUERY PLAN %s;", query)).Scan(&explain).Error
if err != nil {
t.Fatal(err)
}
if !(strings.Contains(strings.ToLower(explain.Extra), "using index")) {
t.Fatalf("query '%s' should use an index, instead the plan was '%s'", query, explain.Extra)
}

}

Check failure on line 381 in stores/sql_test.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.22)

unnecessary trailing newline (whitespace)
}
}
Expand Down

0 comments on commit a376608

Please sign in to comment.