Skip to content

Commit

Permalink
handing for SubqueryScan and limit
Browse files Browse the repository at this point in the history
Signed-off-by: Tanya Gupta <[email protected]>
  • Loading branch information
Tanya Gupta committed Feb 6, 2025
1 parent 1c93737 commit 4428e38
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 3 deletions.
16 changes: 13 additions & 3 deletions contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,18 +596,28 @@ resolve_numeric_typmod_from_exp(Plan *plan, Node *expr)
TargetEntry *tle;
if (plan) outerplan = outerPlan(plan);

/* If we are in parallel mode or have a Sort node then
/* If we are in parallel mode or have a Sort or limit node,
* find the original target list entry from the outer plan
*/
if (plan && outerplan && (
(IsA(plan, Agg) && IsA(outerplan, Gather)) ||
IsA(plan, Gather) ||
IsA(plan, Sort) ||
IsA(plan, GatherMerge)))
IsA(plan, GatherMerge) ||
IsA(plan, Limit)) &&
var->varno == OUTER_VAR)
{
Assert(plan);
Assert(outerplan);
tle = get_tle_by_resno(outerplan->targetlist, var->varattno);
if (IsA(outerplan, SubqueryScan))
{
outerplan = ((SubqueryScan *)outerplan)->subplan;
tle = get_tle_by_resno(outerplan->targetlist, var->varattnosyn);
}
else
{
tle = get_tle_by_resno(outerplan->targetlist, var->varattno);
}
return resolve_numeric_typmod_from_exp(outerplan, (Node *)tle->expr);
}
return var->vartypmod;
Expand Down
2 changes: 2 additions & 0 deletions test/JDBC/expected/BABEL-NUMERIC_EXPR-vu-cleanup.out
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ DROP TABLE BABEL_5454_T7
DROP TABLE BABEL_5454_T8
GO

DROP TABLE BABEL_5454_T9
GO
7 changes: 7 additions & 0 deletions test/JDBC/expected/BABEL-NUMERIC_EXPR-vu-prepare.out
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,10 @@ go
~~ROW COUNT: 1~~


CREATE TABLE BABEL_5454_T9 (id NUMERIC)
GO

INSERT INTO BABEL_5454_T9 VALUES (generate_series(1,100))
GO
~~ROW COUNT: 100~~

9 changes: 9 additions & 0 deletions test/JDBC/expected/BABEL-NUMERIC_EXPR-vu-verify.out
Original file line number Diff line number Diff line change
Expand Up @@ -907,3 +907,12 @@ numeric
~~END~~


-- cte, limit, 5588
WITH cte AS (SELECT TOP 10 (id+1) AS id FROM BABEL_5454_T9 WHERE id >50 ORDER BY id) SELECT TOP 1 1, id FROM cte
GO
~~START~~
int#!#numeric
1#!#52
~~END~~


2 changes: 2 additions & 0 deletions test/JDBC/input/BABEL-NUMERIC_EXPR-vu-cleanup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ DROP TABLE BABEL_5454_T7
DROP TABLE BABEL_5454_T8
GO

DROP TABLE BABEL_5454_T9
GO
5 changes: 5 additions & 0 deletions test/JDBC/input/BABEL-NUMERIC_EXPR-vu-prepare.sql
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ go
INSERT INTO BABEL_5454_T8 VALUES (1, 5000.00);
go

CREATE TABLE BABEL_5454_T9 (id NUMERIC)
GO

INSERT INTO BABEL_5454_T9 VALUES (generate_series(1,100))
GO
4 changes: 4 additions & 0 deletions test/JDBC/input/BABEL-NUMERIC_EXPR-vu-verify.sql
Original file line number Diff line number Diff line change
Expand Up @@ -519,3 +519,7 @@ where id = 1
ORDER BY a
GO

-- cte, limit, 5588
WITH cte AS (SELECT TOP 10 (id+1) AS id FROM BABEL_5454_T9 WHERE id >50 ORDER BY id) SELECT TOP 1 1, id FROM cte
GO

0 comments on commit 4428e38

Please sign in to comment.