t8y2/dbx · error

failed to parse index %s columns: %w

Error message

failed to parse index %s columns: %w

What it means

Returned when parseCatalogAttributeNumbers cannot parse the raw indkey value (the pg/sys_catalog int2vector of index attribute numbers) scanned for an index while listing indexes from the catalog. The error wraps an "invalid attribute number %q" failure with the index name for context. It means the driver could not decode the index's column-number list into []int.

Source

Thrown at agents/drivers/kingbase-go/kingbase_metadata.go:1582

	if err != nil {
		return nil, err
	}
	defer rows.Close()
	type rawIndex struct {
		name, kind      string
		unique, primary bool
		attributeNums   []int
	}
	rawIndexes := []rawIndex{}
	for rows.Next() {
		var item rawIndex
		var raw any
		if err := rows.Scan(&item.name, &item.kind, &item.unique, &item.primary, &raw); err != nil {
			return nil, err
		}
		item.attributeNums, err = parseCatalogAttributeNumbers(raw)
		if err != nil {
			return nil, fmt.Errorf("failed to parse index %s columns: %w", item.name, err)
		}
		rawIndexes = append(rawIndexes, item)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	if len(rawIndexes) == 0 {
		return []indexInfo{}, nil
	}
	attributes, err := s.relationAttributesByNumber(catalog, prefix, schema, table)
	if err != nil {
		return nil, err
	}
	result := make([]indexInfo, 0, len(rawIndexes))
	for _, raw := range rawIndexes {
		item := indexInfo{Name: raw.name, IsUnique: raw.unique, IsPrimary: raw.primary, IndexType: stringPtr(raw.kind), Columns: []string{}, IncludedColumns: []string{}}
		for _, number := range raw.attributeNums {
			if name := attributes[number]; name != "" {

View on GitHub (pinned to c0390bff16)

Solutions

  1. Look at the wrapped "invalid attribute number" message to see which token failed to parse
  2. Identify the offending index (named in the error) and inspect its ix.indkey value in the catalog (SELECT indkey FROM sys_catalog.sys_index WHERE ...)
  3. Drop and recreate the malformed index to regenerate a clean indkey value
  4. Upgrade or fix the Kingbase driver/compat mode so int2vector is returned as a string of integers; or use the WITH ORDINALITY query path if the server supports it

Example fix

// before: query returns raw indkey for all indexes, one bad index fails everything
indexes, err := srv.ListIndexes(schema, table) // fails: failed to parse index myidx columns: invalid attribute number "x"
// after: recreate the bad index in the database
// DROP INDEX myidx; CREATE INDEX myidx ON t(col); then re-run listing
indexes, err := srv.ListIndexes(schema, table)
Defensive patterns

Strategy: try-catch

Validate before calling

// Go: verify indkey values are parseable integer lists before listing indexes
rows, _ := db.Query(`SELECT i.relname, ix.indkey::text FROM sys_catalog.sys_index ix JOIN sys_catalog.sys_class i ON i.oid = ix.indexrelid`)
for rows.Next() {
    var name, indkey string
    rows.Scan(&name, &indkey)
    for _, tok := range strings.Fields(strings.Trim(indkey, "{}")) {
        if _, err := strconv.Atoi(tok); err != nil {
            log.Printf("index %s has unparseable indkey token %q - recreate it", name, tok)
        }
    }
}

Try / catch

indexes, err := srv.ListIndexes(schema, table)
if err != nil {
    var parseErr string
    if _, e := fmt.Sprint(err); strings.Contains(err.Error(), "failed to parse index") {
        parseErr = "catalog indkey malformed; recreate the named index"
    }
    _ = parseErr
    return fmt.Errorf("list indexes: %w", err)
}

Prevention

When it happens

Trigger: Calling the index listing API (e.g. ListIndexes / describe table indexes) using listIndexesWithoutOrdinality on a Kingbase server whose ix.indkey value, after catalog scan, contains tokens that are not plain integers — e.g. a non-standard indkey representation (expression indexes with 0 entries are fine, but corrupted or unexpectedly formatted values fail), or a driver returning an unusual type whose fmt.Sprint output is not a comma/space separated integer list.

Common situations: Older or patched Kingbase versions that serialize int2vector differently; custom index access methods returning unexpected indkey contents; driver type mapping changes so indkey arrives as a non-string type with odd string representation; indexes created by external tools with malformed catalog entries.

Understand the failure class

Related errors


AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05). Data as JSON: /api/errors/c4af7e8e3527bee4. Report an issue: GitHub.