index_cache_lifecycle_test.go 795 B

1234567891011121314151617181920
  1. package executor
  2. import "testing"
  3. func TestDisabledIndexFallsBackRatherThanReturningEmpty(t *testing.T) {
  4. _, schemas, tables := newTestDB(t)
  5. e := newExec(schemas, tables)
  6. execMust(t, e, "CREATE TABLE t (id INTEGER PRIMARY KEY, v INTEGER)")
  7. execMust(t, e, "INSERT INTO t VALUES (1,7)")
  8. execMust(t, e, "CREATE INDEX idx ON t(v)")
  9. execMust(t, e, "SELECT id FROM t WHERE v=7")
  10. // DROP clears derived entries before removing metadata. A concurrent SELECT
  11. // in that interval must fall back, not mistake an unavailable cache for empty.
  12. if err := tables.ClearIndex("idx", "t", []string{"v"}); err != nil {
  13. t.Fatal(err)
  14. }
  15. if got := execMust(t, e, "SELECT id FROM t WHERE v=7").Rows; len(got) != 1 || got[0][0] != int64(1) {
  16. t.Fatalf("disabled cache changed query result: %v", got)
  17. }
  18. }