An error occurred with row records when using parse to analyze SQL

This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 使用parse解析sql时,出现了行记录错误的情况

| username: TiDBer_znMJ0RIQ

【TiDB Usage Environment】Testing
【TiDB Version】 v0.0.0-20240520150715-b3d740f7bb92
【Reproduction Path】Operations performed that led to the issue
Referenced the documentation and wrote a SQL parsing function

func (t *TableStruct) Enter(n ast.Node) (node ast.Node, skipChildren bool) {
	if name, ok := n.(*ast.ColumnName); ok {
		t.colNames = append(t.colNames, name.Name.String())
	} else if tn, ok := n.(*ast.TableName); ok {
		t.tableName = tn.Name.String()
	} else if cs, ok := n.(*ast.CreateTableStmt); ok {
		for _, col := range cs.Cols {
			for _, op := range col.Options {
				if op.Tp == ast.ColumnOptionPrimaryKey {
					t.primaryKey = append(t.primaryKey, col.Name.String())

		for _, constr := range cs.Constraints {
			if constr.Tp == ast.ConstraintPrimaryKey {
				constrKeys := constr.Keys
				for _, key := range constrKeys {
					t.primaryKey = append(t.primaryKey, key.Column.Name.String())

	return n, false

【Encountered Issue: Issue Phenomenon and Impact】
When parsing the create table SQL with a composite primary key, the column display is incorrect

CREATE TABLE users (id INT, email VARCHAR(255), PRIMARY KEY (id, email));

The retrieved column list is [id email id email]

【Resource Configuration】Navigate to TiDB Dashboard - Cluster Info - Hosts and take a screenshot of this page
【Attachments: Screenshots/Logs/Monitoring】

| username: zhaokede | Original post link

Not familiar with Go language.
The returned results can be deduplicated.

| username: TiDBer_H5NdJb5Q | Original post link

Is ColumnName nested?