// getPrimaryKeyColumns returns the list of primary-key column names, in order, for the
// given table.
320093
func getPrimaryKeyColumns(table *schema.Table) []*schema.TableColumn {
	result := make([]*schema.TableColumn, 0, len(table.PKColumns))
	for _, pkColIndex := range table.PKColumns {
		result = append(result, &table.Columns[pkColIndex])
	}
	return result
}
615660
@Override
    public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException
    {
        assert(table != null && !table.isEmpty());
        checkClosed();
        this.sysCatalog.setString(1, "PRIMARYKEYS");
        JDBC4ResultSet res = (JDBC4ResultSet) this.sysCatalog.executeQuery();
        VoltTable vtable = res.getVoltTable().clone(0);

        // Filter the primary keys based on table name
        while (res.next()) {
            if (res.getString("TABLE_NAME").equals(table)) {
                vtable.addRow(res.getRowData());
            }
        }
        return new JDBC4ResultSet(sysCatalog, vtable);
    }
1233765
func PrimaryKey() {
	if f, ok := relationalFieldDefinition(true); ok {
		if f.Datatype != gorma.Integer && f.Datatype != gorma.UUID {
			dslengine.ReportError("Integer and UUID are the only supported Primary Key field types.")
		}

		f.PrimaryKey = true
		f.Nullable = false
		f.Description = "primary key"
		f.Parent.PrimaryKeys = append(f.Parent.PrimaryKeys, f)
	}
}
1217487
func (m *Mocker) FindPrivateKeys(ctx context.Context, keys ...string) ([]string, error) {
	return m.FindPublicKeys(ctx, keys...)
}
219126
func (e *Encoder) getColNames(v interface{}) []string {
	typ := reflect.TypeOf(v)
	val := reflect.ValueOf(v)
	var cols []string
	for i := 0; i < typ.NumField(); i++ {
		// skip unexported
		tF := typ.Field(i)
		if len(tF.PkgPath) > 0 {
			continue
		}
		name := e.getFieldName(tF)
		if name == "" {
			continue
		}
		vF := val.Field(i)
		switch vF.Kind() {
		case reflect.Struct:
			tmp := e.getColNames(vF.Interface())
			cols = append(cols, tmp...)
			continue
		default:
			ok := supportedBaseKind(vF)
			if !ok {
				continue
			}
		}
		cols = append(cols, name)
	}
	return cols
}
1130087
func (x *XC) ListPrivateKeyIDs(ctx context.Context) ([]string, error) {
	return x.secring.KeyIDs(), nil
}
1273720
public static Set<String> getPrimaryKey(DatabaseMetaData metadata, String tableName) throws Exception {
        Set<String> columns = new HashSet<String>();
        ResultSet keys = metadata.getPrimaryKeys(metadata.getConnection().getCatalog(), metadata.getUserName(), tableName);
        while (keys.next()) {
            columns.add(keys.getString(PRIMARY_PK_COL_NAME));
        }
        keys.close();
        return columns;
    }
1192978
func (p *Join) PruneColumns(parentUsedCols []*expression.Column) {
	for _, eqCond := range p.EqualConditions {
		parentUsedCols = append(parentUsedCols, expression.ExtractColumns(eqCond)...)
	}
	for _, leftCond := range p.LeftConditions {
		parentUsedCols = append(parentUsedCols, expression.ExtractColumns(leftCond)...)
	}
	for _, rightCond := range p.RightConditions {
		parentUsedCols = append(parentUsedCols, expression.ExtractColumns(rightCond)...)
	}
	for _, otherCond := range p.OtherConditions {
		parentUsedCols = append(parentUsedCols, expression.ExtractColumns(otherCond)...)
	}
	lChild := p.GetChildByIndex(0).(LogicalPlan)
	rChild := p.GetChildByIndex(1).(LogicalPlan)
	var leftCols, rightCols []*expression.Column
	for _, col := range parentUsedCols {
		if lChild.GetSchema().GetColumnIndex(col) != -1 {
			leftCols = append(leftCols, col)
		} else if rChild.GetSchema().GetColumnIndex(col) != -1 {
			rightCols = append(rightCols, col)
		}
	}
	lChild.PruneColumns(leftCols)
	rChild.PruneColumns(rightCols)
	composedSchema := expression.MergeSchema(lChild.GetSchema(), rChild.GetSchema())
	if p.JoinType == SemiJoin {
		p.schema = lChild.GetSchema().Clone()
	} else if p.JoinType == LeftOuterSemiJoin {
		joinCol := p.schema.Columns[len(p.schema.Columns)-1]
		p.schema = lChild.GetSchema().Clone()
		p.schema.Append(joinCol)
	} else {
		p.schema = composedSchema
	}
}
1167491
func (c *controller) getPrimaryKeyTag(subsys string) ([]byte, uint64, error) {
	c.Lock()
	defer c.Unlock()
	sort.Sort(ByTime(c.keys))
	keys := []*types.EncryptionKey{}
	for _, key := range c.keys {
		if key.Subsystem == subsys {
			keys = append(keys, key)
		}
	}
	return keys[1].Key, keys[1].LamportTime, nil
}
884145
func (fmd *FakeMysqlDaemon) GetColumns(dbName, table string) ([]string, error) {
	return []string{}, nil
}
99565
protected function fetchPrimaryKeys(): array
    {
        $primaryKeys = [];
        foreach ($this->columnSchemas() as $column) {
            if (!empty($column['pk'])) {
                $primaryKeys[] = $column['name'];
            }
        }

        return $primaryKeys;
    }
1092978
func (e *SortExec) keyColumnsLess(i, j int) bool {
	rowI := e.rowChunks.GetRow(e.rowPtrs[i])
	rowJ := e.rowChunks.GetRow(e.rowPtrs[j])
	return e.lessRow(rowI, rowJ)
}
646269
func (sp *SplitParams) areSplitColumnsPrimaryKey() bool {
	pkCols := getPrimaryKeyColumns(sp.splitTableSchema)
	if len(sp.splitColumns) != len(pkCols) {
		return false
	}
	// Compare the names of sp.splitColumns to the names of pkCols.
	for i := 0; i < len(sp.splitColumns); i++ {
		if !sp.splitColumns[i].Name.Equal(pkCols[i].Name) {
			return false
		}
	}
	return true
}
991314
func (ta *Table) GetPKColumn(index int) *TableColumn {
	return &ta.Columns[ta.PKColumns[index]]
}
1372519
func (ds *DataSource) PruneColumns(parentUsedCols []*expression.Column) error {
	used, err := getUsedList(parentUsedCols, ds.schema)
	if err != nil {
		return err
	}

	var (
		handleCol     *expression.Column
		handleColInfo *model.ColumnInfo
	)
	for i := len(used) - 1; i >= 0; i-- {
		if ds.tableInfo.PKIsHandle && mysql.HasPriKeyFlag(ds.Columns[i].Flag) {
			handleCol = ds.schema.Columns[i]
			handleColInfo = ds.Columns[i]
		}
		if !used[i] {
			ds.schema.Columns = append(ds.schema.Columns[:i], ds.schema.Columns[i+1:]...)
			ds.Columns = append(ds.Columns[:i], ds.Columns[i+1:]...)
		}
	}
	for k, cols := range ds.schema.TblID2Handle {
		if ds.schema.ColumnIndex(cols[0]) == -1 {
			delete(ds.schema.TblID2Handle, k)
		}
	}
	// For SQL like `select 1 from t`, tikv's response will be empty if no column is in schema.
	// So we'll force to push one if schema doesn't have any column.
	if ds.schema.Len() == 0 && !infoschema.IsMemoryDB(ds.DBName.L) {
		if handleCol == nil {
			handleCol = ds.newExtraHandleSchemaCol()
			handleColInfo = model.NewExtraHandleColInfo()
		}
		ds.Columns = append(ds.Columns, handleColInfo)
		ds.schema.Append(handleCol)
	}
	return nil
}
109476
func SqTableColumns(db models.XODB, schema string, table string) ([]*models.Column, error) {
	var err error

	// grab
	rows, err := models.SqTableColumns(db, table)
	if err != nil {
		return nil, err
	}

	// fix columns
	var cols []*models.Column
	for _, row := range rows {
		cols = append(cols, &models.Column{
			FieldOrdinal: row.FieldOrdinal,
			ColumnName:   row.ColumnName,
			DataType:     row.DataType,
			NotNull:      row.NotNull,
			DefaultValue: row.DefaultValue,
			IsPrimaryKey: row.PkColIndex != 0,
		})
	}

	return cols, nil
}
759229
func (mysqld *Mysqld) GetPrimaryKeyColumns(dbName, table string) ([]string, error) {
	conn, err := getPoolReconnect(context.TODO(), mysqld.dbaPool)
	if err != nil {
		return nil, err
	}
	defer conn.Recycle()
	qr, err := conn.ExecuteFetch(fmt.Sprintf("SHOW INDEX FROM %s.%s", sqlescape.EscapeID(dbName), sqlescape.EscapeID(table)), 100, true)
	if err != nil {
		return nil, err
	}
	keyNameIndex := -1
	seqInIndexIndex := -1
	columnNameIndex := -1
	for i, field := range qr.Fields {
		switch field.Name {
		case "Key_name":
			keyNameIndex = i
		case "Seq_in_index":
			seqInIndexIndex = i
		case "Column_name":
			columnNameIndex = i
		}
	}
	if keyNameIndex == -1 || seqInIndexIndex == -1 || columnNameIndex == -1 {
		return nil, fmt.Errorf("unknown columns in 'show index' result: %v", qr.Fields)
	}

	columns := make([]string, 0, 5)
	var expectedIndex int64 = 1
	for _, row := range qr.Rows {
		// skip non-primary keys
		if row[keyNameIndex].ToString() != "PRIMARY" {
			continue
		}

		// check the Seq_in_index is always increasing
		seqInIndex, err := sqltypes.ToInt64(row[seqInIndexIndex])
		if err != nil {
			return nil, err
		}
		if seqInIndex != expectedIndex {
			return nil, fmt.Errorf("unexpected index: %v != %v", seqInIndex, expectedIndex)
		}
		expectedIndex++

		columns = append(columns, row[columnNameIndex].ToString())
	}
	return columns, err
}