{"record":{"id":"6ac10df8079987ce","repo":"benbjohnson/litestream","slug":"create-index-w","errorCode":null,"errorMessage":"create index: %w","messagePattern":"create index: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream-test/populate.go","lineNumber":114,"sourceCode":"\t\t\tCREATE TABLE %s (\n\t\t\t\tid INTEGER PRIMARY KEY AUTOINCREMENT,\n\t\t\t\tdata BLOB,\n\t\t\t\ttext_field TEXT,\n\t\t\t\tint_field INTEGER,\n\t\t\t\tfloat_field REAL,\n\t\t\t\ttimestamp INTEGER\n\t\t\t)\n\t\t`, tableName)\n\n\t\tif _, err := db.Exec(createSQL); err != nil {\n\t\t\treturn fmt.Errorf(\"create table %s: %w\", tableName, err)\n\t\t}\n\n\t\tif c.IndexRatio > 0 {\n\t\t\tif rand.Float64() < c.IndexRatio {\n\t\t\t\tindexSQL := fmt.Sprintf(\"CREATE INDEX idx_%s_timestamp ON %s(timestamp)\", tableName, tableName)\n\t\t\t\tif _, err := db.Exec(indexSQL); err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"create index: %w\", err)\n\t\t\t\t}\n\t\t\t}\n\t\t\tif rand.Float64() < c.IndexRatio {\n\t\t\t\tindexSQL := fmt.Sprintf(\"CREATE INDEX idx_%s_int ON %s(int_field)\", tableName, tableName)\n\t\t\t\tif _, err := db.Exec(indexSQL); err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"create index: %w\", err)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\ttotalRows := int(targetBytes / int64(c.RowSize))\n\trowsPerTable := totalRows / c.TableCount\n\tif rowsPerTable == 0 {\n\t\trowsPerTable = 1\n\t}\n\n\tslog.Info(\"Populating database\",","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream-test/populate.go#L96-L132","documentation":"populateDatabase wraps a failed CREATE INDEX ... ON <table>(timestamp) in this error. When IndexRatio triggers indexing, an index on the timestamp column is created after the table is created. Failure here means the optional index could not be built on the freshly created table.","triggerScenarios":"db.Exec(indexSQL) fails: an index named idx_<table>_timestamp already exists from a prior run, the timestamp column is missing (schema drift), or a disk I/O error occurred.","commonSituations":"Re-running populate on a database that already has the indexes; database created by an older tool version with a different schema; insufficient disk space for large index builds.","solutions":["Drop existing idx_* indexes or start from a fresh database file.","Confirm the table schema includes the timestamp column.","Free disk space if the wrapped error is SQLITE_FULL.","Use CREATE INDEX IF NOT EXISTS in a patched build to make re-runs idempotent."],"exampleFix":"// before\nindexSQL := fmt.Sprintf(\"CREATE INDEX idx_%s_timestamp ON %s(timestamp)\", tableName, tableName)\n// after\nindexSQL := fmt.Sprintf(\"CREATE INDEX IF NOT EXISTS idx_%s_timestamp ON %s(timestamp)\", tableName, tableName)","handlingStrategy":"validation","validationCode":"var exists int\nif err := db.QueryRow(\"SELECT COUNT(*) FROM sqlite_master WHERE type='index' AND name=?\", fmt.Sprintf(\"idx_%s_timestamp\", tableName)).Scan(&exists); err == nil && exists > 0 {\n    // skip index creation\n}","typeGuard":null,"tryCatchPattern":"if _, err := db.Exec(indexSQL); err != nil {\n    if strings.Contains(err.Error(), \"already exists\") {\n        return nil // idempotent skip\n    }\n    return fmt.Errorf(\"create index: %w\", err)\n}","preventionTips":["Use CREATE INDEX IF NOT EXISTS for repeatable runs.","Start from a clean database for deterministic results.","Verify the timestamp column exists in the created schema.","Free disk space before index builds on large tables."],"tags":["sqlite","index","ddl"],"backgroundTag":"database-query-failed","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}