pg库,如果oid索引,会导致判断出错 #2103

Open
opened 2022-01-19 07:17:08 +00:00 by 4color · 3 comments
Contributor

image

postgres.go GetIndexes 方法

func (db *postgres) GetIndexes(queryer core.Queryer, ctx context.Context, tableName string) (map[string]*schemas.Index, error) {
	args := []interface{}{tableName}
	s := "SELECT indexname, indexdef FROM pg_indexes WHERE tablename=$1"
	if len(db.getSchema()) != 0 {
		args = append(args, db.getSchema())
		s = s + " AND schemaname=$2"
	}

	rows, err := queryer.QueryContext(ctx, s, args...)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
    
    //这里得到的字段名是 oid 
    colNames = getIndexColName(indexdef)
再回到  engin.go loadTableInfo 这个中,判断列是否有这个索引名,就会出错
   if col := table.GetColumn(colName); col != nil {
col.Indexes[index.Name] = index.Type
} else {
return fmt.Errorf("Unknown col %s seq %d, in index %v of table %v, columns %v", name, seq, index.Name, table.Name, table.ColumnsSeq())
}
![image](/attachments/5dc8e120-85ef-4121-8bc2-5990d197f67b) postgres.go GetIndexes 方法 ``` func (db *postgres) GetIndexes(queryer core.Queryer, ctx context.Context, tableName string) (map[string]*schemas.Index, error) { args := []interface{}{tableName} s := "SELECT indexname, indexdef FROM pg_indexes WHERE tablename=$1" if len(db.getSchema()) != 0 { args = append(args, db.getSchema()) s = s + " AND schemaname=$2" } rows, err := queryer.QueryContext(ctx, s, args...) if err != nil { return nil, err } defer rows.Close() ``` ``` //这里得到的字段名是 oid colNames = getIndexColName(indexdef) ``` 再回到 engin.go loadTableInfo 这个中,判断列是否有这个索引名,就会出错 ``` if col := table.GetColumn(colName); col != nil { col.Indexes[index.Name] = index.Type } else { return fmt.Errorf("Unknown col %s seq %d, in index %v of table %v, columns %v", name, seq, index.Name, table.Name, table.ColumnsSeq()) } ```
Author
Contributor

按我的理解,应该忽略这个索引。

按我的理解,应该忽略这个索引。
Owner

Please send a pull request.

Please send a pull request.
Contributor

#2105 (comment)

已修复

https://gitea.com/xorm/xorm/pulls/2105#issue-115446 已修复
Sign in to join this conversation.
No Milestone
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/xorm#2103
No description provided.