Example #1
0
// makeRowDeleter creates a rowDeleter for the given table.
//
// The returned rowDeleter contains a fetchCols field that defines the
// expectation of which values are passed as values to deleteRow.
func makeRowDeleter(
	tableDesc *sqlbase.TableDescriptor,
) (rowDeleter, error) {
	// TODO(dan): makeRowDeleter should take a param for the sql rows needed for
	// returningHelper, etc.
	requestedCols := tableDesc.Columns

	indexes := tableDesc.Indexes
	for _, m := range tableDesc.Mutations {
		if index := m.GetIndex(); index != nil {
			indexes = append(indexes, *index)
		}
	}

	fetchCols := requestedCols[:len(requestedCols):len(requestedCols)]
	fetchColIDtoRowIndex := colIDtoRowIndexFromCols(fetchCols)
	for _, index := range indexes {
		for _, colID := range index.ColumnIDs {
			if _, ok := fetchColIDtoRowIndex[colID]; !ok {
				// TODO(dan): What about non-active columns?
				col, err := tableDesc.FindActiveColumnByID(colID)
				if err != nil {
					return rowDeleter{}, err
				}
				fetchColIDtoRowIndex[colID] = len(fetchCols)
				fetchCols = append(fetchCols, *col)
			}
		}
	}

	rd := rowDeleter{
		helper:               rowHelper{tableDesc: tableDesc, indexes: indexes},
		fetchCols:            fetchCols,
		fetchColIDtoRowIndex: fetchColIDtoRowIndex,
	}
	return rd, nil
}