github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/delegate/show_sessions.go (about) 1 // Copyright 2017 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 "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" 15 "github.com/cockroachdb/cockroach/pkg/sql/sqlbase" 16 ) 17 18 func (d *delegator) delegateShowSessions(n *tree.ShowSessions) (tree.Statement, error) { 19 const query = `SELECT node_id, session_id, user_name, client_address, application_name, active_queries, last_active_query, session_start, oldest_query_start FROM crdb_internal.` 20 table := `node_sessions` 21 if n.Cluster { 22 table = `cluster_sessions` 23 } 24 var filter string 25 if !n.All { 26 filter = " WHERE application_name NOT LIKE '" + sqlbase.InternalAppNamePrefix + "%'" 27 } 28 return parse(query + table + filter) 29 }