Repository: dolthub/dolt
File: go/libraries/doltcore/sqle/index/dolt_index.go (Go)

Code before:
	}
	return indexes, nil
}

func DoltToFromCommitIndexes(tbl string, sch schema.Schema) (indexes []sql.Index) {
	for _, toFrom := range []string{"to", "from"} {
		cols := make([]schema.Column, 0, len(sch.GetAllCols().GetColumns())+2)
		cols = append(cols,
			schema.NewColumn(ToCommitIndexId, schema.DiffCommitTag, types.StringKind, false),
			schema.NewColumn(FromCommitIndexId, schema.DiffCommitTag, types.StringKind, false),
		)
		for _, col := range sch.GetPKCols().GetColumns() {
			col.Name = toFrom + "_" + col.Name
			cols = append(cols, col)
		}

		indexes = append(indexes, &doltIndex{
			id:                            "commits_" + toFrom,
			tblName:                       doltdb.DoltCommitDiffTablePrefix + tbl,
			columns:                       cols,
			unique:                        true,
			comment:                       "",
			order:                         sql.IndexOrderNone,
			constrainedToLookupExpression: false,
			// We pass a nil ValueStore into the key builder, because we don't have one. This would cause an issue
			// if any of the columns uss Adaptive encoding, but that shouldn't be possible in the primary key.
			keyBld: val.NewTupleBuilder(sch.GetKeyDescriptor(nil), nil),
		})
	}
	return indexes
}

// MockIndex returns a sql.Index that is not backed by an actual datastore. It's useful for system tables and
// system table functions provide indexes but produce their rows at execution time based on the provided `IndexLookup`
func MockIndex(dbName, tableName, columnName string, columnType types.NomsKind, unique bool) (index *doltIndex) {
	return &doltIndex{
		id:      columnName,
		tblName: tableName,
		dbName:  dbName,
		columns: []schema.Column{
			schema.NewColumn(columnName, 0, columnType, false),
		},
		indexSch:                      nil,
		tableSch:                      nil,
		unique:                        unique,
		comment:                       "",
		vrw:                           nil,
		ns:                            nil,
		order:                         sql.IndexOrderNone,
		constrainedToLookupExpression: false,
	}

Review comment (suggestion):
```suggestion
			// if any of the columns use Adaptive encoding, but that shouldn't be possible in the primary key.
```

Code after:
	}
	return indexes, nil
}

func DoltToFromCommitIndexes(tbl string, sch schema.Schema) (indexes []sql.Index) {
	for _, toFrom := range []string{"to", "from"} {
		cols := make([]schema.Column, 0, len(sch.GetAllCols().GetColumns())+2)
		cols = append(cols,
			schema.NewColumn(ToCommitIndexId, schema.DiffCommitTag, types.StringKind, false),
			schema.NewColumn(FromCommitIndexId, schema.DiffCommitTag, types.StringKind, false),
		)
		for _, col := range sch.GetPKCols().GetColumns() {
			col.Name = toFrom + "_" + col.Name
			cols = append(cols, col)
		}

		indexes = append(indexes, &doltIndex{
			id:                            "commits_" + toFrom,
			tblName:                       doltdb.DoltCommitDiffTablePrefix + tbl,
			columns:                       cols,
			unique:                        true,
			comment:                       "",
			order:                         sql.IndexOrderNone,
			constrainedToLookupExpression: false,
			// We pass a nil ValueStore into the key builder, because we don't have one. This would cause an issue
			// if any of the columns use Adaptive encoding, but that shouldn't be possible in the primary key.
			keyBld: val.NewTupleBuilder(sch.GetKeyDescriptor(nil), nil),
		})
	}
	return indexes
}

// MockIndex returns a sql.Index that is not backed by an actual datastore. It's useful for system tables and
// system table functions provide indexes but produce their rows at execution time based on the provided `IndexLookup`
func MockIndex(dbName, tableName, columnName string, columnType types.NomsKind, unique bool) (index *doltIndex) {
	return &doltIndex{
		id:      columnName,
		tblName: tableName,
		dbName:  dbName,
		columns: []schema.Column{
			schema.NewColumn(columnName, 0, columnType, false),
		},
		indexSch:                      nil,
		tableSch:                      nil,
		unique:                        unique,
		comment:                       "",
		vrw:                           nil,
		ns:                            nil,
		order:                         sql.IndexOrderNone,
		constrainedToLookupExpression: false,
	}