-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathplan_ordering.go
90 lines (79 loc) · 2.53 KB
/
plan_ordering.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2017 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
package sql
import "github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo"
// ReqOrdering is the ordering that must be preserved by an operator when it is
// distributed. It is used to configure DistSQL with the orderings it needs to
// maintain when joining streams.
type ReqOrdering = colinfo.ColumnOrdering
// planReqOrdering describes known ordering information for the rows generated by
// this node. The ordering information includes columns the output is ordered
// by and columns for which we know all rows have the same value.
func planReqOrdering(plan planNode) ReqOrdering {
switch n := plan.(type) {
case *limitNode:
return planReqOrdering(n.plan)
case *max1RowNode:
return planReqOrdering(n.plan)
case *spoolNode:
return planReqOrdering(n.source)
case *saveTableNode:
return planReqOrdering(n.source)
case *serializeNode:
return planReqOrdering(n.source)
case *deleteNode:
if n.run.rowsNeeded {
return planReqOrdering(n.source)
}
case *filterNode:
return n.reqOrdering
case *groupNode:
return n.reqOrdering
case *distinctNode:
return n.reqOrdering
case *indexJoinNode:
return n.reqOrdering
case *windowNode:
// TODO: window partitions can be ordered if the source is ordered
// appropriately.
case *joinNode:
return n.reqOrdering
case *unionNode:
return n.reqOrdering
case *insertNode, *insertFastPathNode:
// TODO(knz): RETURNING is ordered by the PK.
case *updateNode, *upsertNode:
// After an update, the original order may have been destroyed.
// For example, if the PK is updated by a SET expression.
// So we can't assume any ordering.
//
// TODO(knz/radu): this can be refined by an analysis which
// determines whether the columns that participate in the ordering
// of the source are being updated. If they are not, the source
// ordering can be propagated.
case *scanNode:
return n.reqOrdering
case *ordinalityNode:
return n.reqOrdering
case *renderNode:
return n.reqOrdering
case *sortNode:
return n.ordering
case *topKNode:
return n.ordering
case *lookupJoinNode:
return n.reqOrdering
case *invertedJoinNode:
return n.reqOrdering
case *zigzagJoinNode:
return n.reqOrdering
}
return nil
}