Debian Codegraph @

impossible_query.go

raw symbols SCIP
1 /*
2 Copyright 2017 Google Inc.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreedto in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 package sqlparser
18
19 // FormatImpossibleQuery creates an impossible query in a TrackedBuffer.
20 // An impossible query is a modified version of a query where all selects have where clauses that are
21 // impossible for mysql to resolve. This is used in the vtgate and vttablet:
22 //
23 // - In the vtgate it's used for joins: if the first query returns no result, then vtgate uses the impossible
24 // query just to fetch field info from vttablet
25 // - In the vttablet, it's just an optimization: the field info is fetched once form MySQL, cached and reused
26 // for subsequent queries
27 func FormatImpossibleQuery(buf *TrackedBuffer, node SQLNode) {
28 switch node := node.(type) {
29 case *Select:
30 buf.Myprintf("select %v from %v where 1 != 1", node.SelectExprs, node.From)
31 if node.GroupBy != nil {
32 node.GroupBy.Format(buf)
33 }
34 case *Union:
35 buf.Myprintf("%v %s %v", node.Left, node.Type, node.Right)
36 default:
37 node.Format(buf)
38 }
39 }