本文整理汇总了Golang中github.com/cockroachdb/cockroach/sql/parser.QualifiedName.Index方法的典型用法代码示例。如果您正苦于以下问题:Golang QualifiedName.Index方法的具体用法?Golang QualifiedName.Index怎么用?Golang QualifiedName.Index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cockroachdb/cockroach/sql/parser.QualifiedName
的用法示例。
在下文中一共展示了QualifiedName.Index方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: initTable
// Initializes a scanNode with a tableName. Returns the table or index name that can be used for
// fully-qualified columns if an alias is not specified.
func (n *scanNode) initTable(p *planner, tableName *parser.QualifiedName) (string, *roachpb.Error) {
if n.desc, n.pErr = p.getTableLease(tableName); n.pErr != nil {
return "", n.pErr
}
if err := p.checkPrivilege(&n.desc, privilege.SELECT); err != nil {
return "", roachpb.NewError(err)
}
alias := n.desc.Name
indexName := tableName.Index()
if indexName != "" && !equalName(n.desc.PrimaryIndex.Name, indexName) {
for i := range n.desc.Indexes {
if equalName(n.desc.Indexes[i].Name, indexName) {
// Remove all but the matching index from the descriptor.
n.desc.Indexes = n.desc.Indexes[i : i+1]
n.index = &n.desc.Indexes[0]
break
}
}
if n.index == nil {
n.pErr = roachpb.NewUErrorf("index \"%s\" not found", indexName)
return "", n.pErr
}
// Use the index name instead of the table name for fully-qualified columns in the
// expression.
alias = n.index.Name
// Strip out any columns from the table that are not present in the
// index.
visibleCols := make([]ColumnDescriptor, 0, len(n.index.ColumnIDs)+len(n.index.ImplicitColumnIDs))
for _, colID := range n.index.ColumnIDs {
col, err := n.desc.FindColumnByID(colID)
n.pErr = roachpb.NewError(err)
if n.pErr != nil {
return "", n.pErr
}
visibleCols = append(visibleCols, *col)
}
for _, colID := range n.index.ImplicitColumnIDs {
col, err := n.desc.FindColumnByID(colID)
n.pErr = roachpb.NewError(err)
if n.pErr != nil {
return "", n.pErr
}
visibleCols = append(visibleCols, *col)
}
n.isSecondaryIndex = true
n.initVisibleCols(visibleCols, len(n.index.ImplicitColumnIDs))
} else {
n.initDescDefaults()
}
return alias, nil
}