Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion qpmodel/DataType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,10 @@ public JoinQueryRef(List<TableRef> tables, List<string> joinops, List<Expr> cons
{
case "join": type = JoinType.Inner; break;
case "leftjoin": case "leftouterjoin": type = JoinType.Left; break;
case "crossjoin":
case "crossjoin": type = JoinType.Inner; break;
case "naturaljoin": type = JoinType.Inner; break;
case "naturalleftjoin":
case "naturalleftouterjoin": type = JoinType.Left; break;
Comment on lines +610 to +612

Copilot AI Apr 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JoinQueryRef maps naturaljoin/naturalleftjoin to regular join types, but no code builds the implicit equality predicates on common column names. With constraints_ being null for NATURAL JOIN, the plan becomes an unconstrained INNER/LEFT join (i.e., effectively a CROSS join), which is incorrect when tables share column names. Consider either implementing NATURAL JOIN predicate generation during binding/planning or rejecting NATURAL JOIN with a clear error until it is supported.

Suggested change
case "naturaljoin": type = JoinType.Inner; break;
case "naturalleftjoin":
case "naturalleftouterjoin": type = JoinType.Left; break;
case "naturaljoin":
case "naturalleftjoin":
case "naturalleftouterjoin":
throw new SemanticAnalyzeException("NATURAL JOIN is not supported because implicit join predicates are not implemented");

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. The NATURAL JOIN mapping here is intentionally minimal — it prevents a crash on NATURAL JOIN syntax by mapping to the correct join type, but does not yet build implicit equality predicates on common column names. This is documented as a limitation. Full NATURAL JOIN support (auto-generating equi-join conditions from shared column names) is out of scope for this bug-fix PR.

case "rightjoin":
case "rightouterjoin":
case "fulljoin":
Expand Down
2 changes: 2 additions & 0 deletions qpmodel/Expr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,8 @@ public static ConstExpr MakeConst(Value val, ColumnType type, string outputName
ConstExpr ret;
if (type is CharType || type is VarCharType || type is DateTimeType)
ret = new ConstExpr($"'{val}'", type);
else if (type is IntType && val != null)
ret = new ConstExpr($"{Convert.ToInt32(val)}", type);
else
ret = new ConstExpr($"{val}", type);
ret.outputName_ = outputName;
Expand Down
Loading
Loading