refactor(go): drop redundant daily mileage vin index

This commit is contained in:
lingniu
2026-07-03 07:36:53 +08:00
parent cb63ceec2e
commit 9345fe60b5
3 changed files with 4 additions and 1 deletions

View File

@@ -129,6 +129,9 @@ func TestWriterEnsuresSchemaAndUpsertsDailyMileage(t *testing.T) {
if !strings.Contains(exec.calls[0].query, "PRIMARY KEY (vin, stat_date, protocol)") {
t.Fatalf("daily mileage table should key by vin/stat_date/protocol: %s", exec.calls[0].query)
}
if strings.Contains(exec.calls[0].query, "KEY idx_vin (vin)") {
t.Fatalf("daily mileage table should not keep redundant vin index covered by the primary key: %s", exec.calls[0].query)
}
if len(exec.calls) != 2 {
t.Fatalf("exec calls = %d", len(exec.calls))
}

View File

@@ -10,7 +10,6 @@ const DailyMileageTableSQL = `CREATE TABLE IF NOT EXISTS vehicle_daily_mileage (
sample_count BIGINT NOT NULL DEFAULT 0,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (vin, stat_date, protocol),
KEY idx_vin (vin),
KEY idx_stat_date (stat_date),
KEY idx_protocol_date (protocol, stat_date)
)`