Table Reference Nodes¶
Table Reference nodes represent how tables and data sources are specified and combined in SQL statements. They handle everything from simple table names to complex join operations and derived tables.
Overview¶
Table reference nodes define the data sources for SQL operations. They appear primarily in FROM clauses and can represent physical tables, views, subqueries, or combinations thereof through joins.
Table Reference Types¶
Basic Table References¶
- Table Nodes -
TTable - Physical tables and views
- Table aliases and schema qualification
-
Database-specific table hints
-
Table Lists -
TTableList - Collections of table references
- Comma-separated table lists
- Cartesian product implications
Join Operations¶
- JOIN Nodes -
TJoinExpr - All join types (INNER, LEFT, RIGHT, FULL)
- Join conditions and expressions
-
Multi-table join chains
-
Join Conditions
- ON clause specifications
- USING clause syntax
- Natural join handling
Advanced Table Sources¶
- Derived Tables - Subqueries in FROM
- Subquery table expressions
- Common Table Expressions (CTEs)
-
Inline views and virtual tables
-
Table Functions
- Table-valued functions
- UNNEST operations
- Lateral joins and table expressions
Table Reference Structure¶
Basic Table Structure¶
1 2 3 4 5 | |
Join Structure¶
1 2 3 4 5 | |
Common Usage Patterns¶
Extracting All Table Names¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
Analyzing Join Relationships¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | |
Building Table Lineage¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |
Join Types and Their Representations¶
| SQL Syntax | AST Representation | Join Type |
|---|---|---|
INNER JOIN |
TJoinExpr with jointype = inner |
Inner join |
LEFT JOIN |
TJoinExpr with jointype = left |
Left outer join |
RIGHT JOIN |
TJoinExpr with jointype = right |
Right outer join |
FULL JOIN |
TJoinExpr with jointype = full |
Full outer join |
CROSS JOIN |
TJoinExpr with jointype = cross |
Cross join |
, (comma) |
TTableList |
Implicit cross join |
Database-Specific Features¶
SQL Server¶
- Table hints (
WITH (NOLOCK),WITH (INDEX=...)) APPLYoperators (CROSS APPLY,OUTER APPLY)- Temporal table syntax (
FOR SYSTEM_TIME)
PostgreSQL¶
LATERALjoins for correlated subqueries- Table functions in FROM clause
- Advanced CTE features (
RECURSIVE)
Oracle¶
- Partition-wise joins
- Flashback query syntax (
AS OF) - Hierarchical query syntax in FROM
MySQL¶
- Index hints (
USE INDEX,FORCE INDEX) - Partition pruning syntax
- Engine-specific table options
Performance Considerations¶
Join Order Analysis¶
1 2 3 4 5 | |
Table Size Estimation¶
1 2 3 4 5 | |
See Also¶
- FROM Clause - Container for table references
- JOIN Clause - Join-specific documentation
- SQL Statements - Statements containing table references
- Expressions - Join conditions and table expressions