github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/delegate/show_database_indexes.go (about) 1 // Copyright 2019 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package delegate 12 13 import ( 14 "fmt" 15 16 "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" 17 ) 18 19 func (d *delegator) delegateShowDatabaseIndexes( 20 n *tree.ShowDatabaseIndexes, 21 ) (tree.Statement, error) { 22 getAllIndexesQuery := ` 23 SELECT 24 table_name, 25 index_name, 26 non_unique::BOOL, 27 seq_in_index, 28 column_name, 29 direction, 30 storing::BOOL, 31 implicit::BOOL` 32 33 if n.WithComment { 34 getAllIndexesQuery += `, 35 obj_description(pg_class.oid) AS comment` 36 } 37 38 getAllIndexesQuery += ` 39 FROM 40 %s.information_schema.statistics` 41 42 if n.WithComment { 43 getAllIndexesQuery += ` 44 LEFT JOIN pg_class ON 45 statistics.index_name = pg_class.relname` 46 } 47 48 return parse(fmt.Sprintf(getAllIndexesQuery, n.Database.String())) 49 }