Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a2a0e68
planner: lateral join support (WIP)
terry1purcell Jan 19, 2026
67a35c4
add bazel
terry1purcell Jan 19, 2026
87f1814
review1
terry1purcell Jan 19, 2026
d57c75d
parser: regenerate keywords.go after adding LATERAL keyword
terry1purcell Jan 19, 2026
f8ff972
improve testcases
terry1purcell Jan 19, 2026
9d0fc05
add bazel2
terry1purcell Jan 19, 2026
a0f82b0
improve testcases2
terry1purcell Jan 19, 2026
d1aca20
add recursion
terry1purcell Jan 20, 2026
7d5d4fb
build error
terry1purcell Jan 20, 2026
1ae8ef3
parser: update TestKeywordsLength for LATERAL keyword
terry1purcell Jan 20, 2026
db48f75
planner: add integration tests for LATERAL join
terry1purcell Jan 20, 2026
b32eb12
*: update errors.toml for LATERAL join error
terry1purcell Jan 20, 2026
43146e3
planner: fix error validation in lateral_join_test.go
terry1purcell Jan 20, 2026
1d8c4d2
planner: reject NATURAL JOIN and USING clause with LATERAL
terry1purcell Jan 20, 2026
a952b9b
planner: harmonize DBName handling comments for derived tables
terry1purcell Jan 20, 2026
78f1034
planner: set curClause to onClause before processing ON condition in …
terry1purcell Jan 20, 2026
e6fd267
planner: consolidate LATERAL cleanup into single defer for consistency
terry1purcell Jan 20, 2026
1822e15
planner: add FullSchema/FullNames and ResetNotNullFlag for LATERAL
terry1purcell Jan 20, 2026
f180d9d
planner: clone hidden names when cloning output names to prevent muta…
terry1purcell Jan 20, 2026
7ab4e47
Revert "planner: clone hidden names when cloning output names to prev…
terry1purcell Jan 20, 2026
82a6ec4
planner: fix CTE regression by reverting problematic recursion changes
terry1purcell Jan 20, 2026
d34e897
review comments - so many
terry1purcell Jan 20, 2026
faf3c54
review comments2
terry1purcell Jan 21, 2026
7e124ae
regenerate tests
terry1purcell Jan 21, 2026
d56d555
regenerate tests2
terry1purcell Jan 21, 2026
3c17be7
update comment1
terry1purcell Jan 21, 2026
a77db02
merge conflict
terry1purcell Feb 2, 2026
0d1532e
testcase updates after rebase
terry1purcell Feb 3, 2026
2b970e4
Update pkg/parser/lateral_test.go
terry1purcell Feb 3, 2026
883caf9
remove dead code
terry1purcell Feb 3, 2026
59654e8
pantheon review comments
terry1purcell Feb 3, 2026
9561895
copilot review comments2
terry1purcell Feb 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("@bazel_gazelle//:def.bzl", "gazelle")

exports_files([
Expand All @@ -23,3 +24,19 @@ xcode_version(
name = "xcode_version",
version = "10.0",
)

go_library(
name = "tidb_lib",
srcs = ["test_lateral_simple.go"],
importpath = "github.com/pingcap/tidb",
deps = [
"//pkg/parser",
"//pkg/parser/format",
"//pkg/types/parser_driver",
],
)

go_binary(
name = "tidb",
embed = [":tidb_lib"],
)
1 change: 1 addition & 0 deletions pkg/errno/errcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,7 @@ const (
ErrDefValGeneratedNamedFunctionIsNotAllowed = 3770
ErrFKIncompatibleColumns = 3780
ErrFunctionalIndexRowValueIsNotAllowed = 3800
ErrInvalidLateralJoin = 3809
ErrNonBooleanExprForCheckConstraint = 3812
ErrColumnCheckConstraintReferencesOtherColumn = 3813
ErrCheckConstraintNamedFunctionIsNotAllowed = 3814
Expand Down
1 change: 1 addition & 0 deletions pkg/errno/errname.go
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,7 @@ var MySQLErrName = map[uint16]*mysql.ErrMessage{
ErrFunctionalIndexOnField: mysql.Message("Expression index on a column is not supported. Consider using a regular index instead", nil),
ErrFKIncompatibleColumns: mysql.Message("Referencing column '%s' and referenced column '%s' in foreign key constraint '%s' are incompatible.", nil),
ErrFunctionalIndexRowValueIsNotAllowed: mysql.Message("Expression of expression index '%s' cannot refer to a row value", nil),
ErrInvalidLateralJoin: mysql.Message("Invalid use of LATERAL: %s", nil),
ErrNonBooleanExprForCheckConstraint: mysql.Message("An expression of non-boolean type specified to a check constraint '%s'.", nil),
ErrColumnCheckConstraintReferencesOtherColumn: mysql.Message("Column check constraint '%s' references other column.", nil),
ErrCheckConstraintNamedFunctionIsNotAllowed: mysql.Message("An expression of a check constraint '%s' contains disallowed function: %s.", nil),
Expand Down
10 changes: 10 additions & 0 deletions pkg/parser/ast/dml.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,11 @@ type TableSource struct {

// AsName is the alias name of the table source.
AsName CIStr

// Lateral indicates whether this is a LATERAL derived table.
// MySQL 8.0+ syntax: FROM t1, LATERAL (SELECT ...) AS dt
// LATERAL allows the derived table to reference columns from tables to its left.
Lateral bool
}

func (*TableSource) resultSet() {}
Expand All @@ -547,6 +552,11 @@ func (n *TableSource) Restore(ctx *format.RestoreCtx) error {
needParen = true
}

// Output LATERAL keyword if this is a LATERAL derived table
if n.Lateral {
ctx.WriteKeyWord("LATERAL ")
}

if tn, tnCase := n.Source.(*TableName); tnCase {
if needParen {
ctx.WritePlain("(")
Expand Down
1 change: 1 addition & 0 deletions pkg/parser/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ var tokenMap = map[string]int{
"LAST_BACKUP": lastBackup,
"LAST": last,
"LASTVAL": lastval,
"LATERAL": lateral,
"LEADER": leader,
"LEADER_CONSTRAINTS": leaderConstraints,
"LEADING": leading,
Expand Down
1 change: 1 addition & 0 deletions pkg/parser/mysql/errcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,7 @@ const (
ErrFunctionalIndexOnField = 3762
ErrFKIncompatibleColumns = 3780
ErrFunctionalIndexRowValueIsNotAllowed = 3800
ErrInvalidLateralJoin = 3809
ErrDependentByFunctionalIndex = 3837
ErrInvalidJSONType = 3853
ErrInvalidJsonValueForFuncIndex = 3903 //nolint: revive
Expand Down
Loading