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
//! Module for planning SQL statements.
//!
//! Planning phases:
//!
//! 1. Resolve
//! 2. Bind
//! 3. Plan
//!
//! # Resolving
//!
//! First step in SQL planning. Walks the AST to resolve all tables and functions in
//! the query. This retains the structure of the AST and annotates tables and
//! functions with their catalog entries.
//!
//! Resolving is async to allow for hitting remote resources (e.g. determining the
//! schema of file, or contacting an external database).
//!
//! This step also determines if we should be flipped to hybrid execution. When
//! walking the AST, unknown references will be tracked. At the the end of
//! resolving, we check for any unknown references, and if we have any, we send the
//! statement a remote server. The remote side should complete resolving, and
//! continue on with the remaining plan steps.
//!
//! # Binding
//!
//! Walk the AST and transform the query into something more amenable to planning.
//!
//! During this phase, we build up a bind context which tracks "table-producing"
//! steps within the query. This context is the basis for determining scoping within
//! the query.
//!
//! The bound statement produces is a halfway point between the AST and logical
//! plan.
//!
//! # Planning
//!
//! Walks the bound statement and produces a logical plan.