Ejemplo n.º 1
0
func makeBaseFKHelper(
	txn *client.Txn,
	otherTables TablesByID,
	writeIdx sqlbase.IndexDescriptor,
	ref *sqlbase.TableAndIndexID,
	colMap map[sqlbase.ColumnID]int, // col ids (for idx being written) to row offset.
) (baseFKHelper, error) {
	b := baseFKHelper{txn: txn, writeIdx: writeIdx, searchPrefix: ref.IndexKeyPrefix()}
	searchTable, ok := otherTables[ref.Table]
	if !ok {
		return b, util.Errorf("referenced table %d not in provided table map %+v", ref.Table, otherTables)
	}
	b.searchTable = searchTable
	searchIdx, err := searchTable.FindIndexByID(ref.Index)
	if err != nil {
		return b, err
	}
	b.searchIdx = searchIdx
	ids := colIDtoRowIndexFromCols(searchTable.Columns)
	needed := make([]bool, len(ids))
	for _, i := range searchIdx.ColumnIDs {
		needed[ids[i]] = true
	}
	isSecondary := searchTable.PrimaryIndex.ID != searchIdx.ID
	err = b.rf.Init(searchTable, ids, searchIdx, false, isSecondary, searchTable.Columns, needed)
	if err != nil {
		return b, err
	}

	b.ids = make(map[sqlbase.ColumnID]int, len(writeIdx.ColumnIDs))
	for i := range writeIdx.ColumnIDs {
		b.ids[searchIdx.ColumnIDs[i]] = colMap[writeIdx.ColumnIDs[i]]
	}
	return b, nil
}
Ejemplo n.º 2
0
func makeBaseFKHelepr(
	txn *client.Txn,
	writeIdx sqlbase.IndexDescriptor,
	ref *sqlbase.TableAndIndexID,
	colMap map[sqlbase.ColumnID]int, // col ids (for idx being written) to row offset.
) (baseFKHelper, error) {
	b := baseFKHelper{txn: txn, writeIdx: writeIdx, searchPrefix: ref.IndexKeyPrefix()}
	// TODO(dt): Get a lease manager here and use that.
	searchTable, err := getTableDescFromID(txn, ref.Table)
	if err != nil {
		return b, err
	}
	b.searchTable = searchTable
	searchIdx, err := searchTable.FindIndexByID(ref.Index)
	if err != nil {
		return b, err
	}
	b.searchIdx = searchIdx
	ids := colIDtoRowIndexFromCols(searchTable.Columns)
	needed := make([]bool, len(ids))
	for _, i := range searchIdx.ColumnIDs {
		needed[ids[i]] = true
	}
	isSecondary := searchTable.PrimaryIndex.ID != searchIdx.ID
	err = b.rf.Init(searchTable, ids, searchIdx, false, isSecondary, searchTable.Columns, needed)
	if err != nil {
		return b, err
	}

	b.ids = make(map[sqlbase.ColumnID]int, len(writeIdx.ColumnIDs))
	for i := range writeIdx.ColumnIDs {
		b.ids[searchIdx.ColumnIDs[i]] = colMap[writeIdx.ColumnIDs[i]]
	}
	return b, nil
}