本文整理匯總了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
}