Skip to content

Commit 13d53aa

Browse files
committed
Doc/improve confusing, inefficient tests to locate CTID variable.
The IsCTIDVar() tests in nodeTidscan.c and nodeTidrangescan.c look buggy at first sight: they aren't checking that the varno matches the table to be scanned. Actually they're safe because any Var in a scan-level qual must be for the correct table ... but if we're depending on that, it's pretty pointless to verify varlevelsup. (Besides which, varlevelsup is *always* zero at execution, since we've flattened the rangetable long since.) Remove the useless varlevelsup check, and instead add some commentary explaining why we don't need to check varno. Noted while fooling with a planner change that causes the order of "t1.ctid = t2.ctid" to change in some tidscan.sql tests; I was briefly fooled into thinking there was a live bug here.
1 parent 0e972f5 commit 13d53aa

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/backend/executor/nodeTidrangescan.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,16 @@
2525
#include "utils/rel.h"
2626

2727

28+
/*
29+
* It's sufficient to check varattno to identify the CTID variable, as any
30+
* Var in the relation scan qual must be for our table. (Even if it's a
31+
* parameterized scan referencing some other table's CTID, the other table's
32+
* Var would have become a Param by the time it gets here.)
33+
*/
2834
#define IsCTIDVar(node) \
2935
((node) != NULL && \
3036
IsA((node), Var) && \
31-
((Var *) (node))->varattno == SelfItemPointerAttributeNumber && \
32-
((Var *) (node))->varlevelsup == 0)
37+
((Var *) (node))->varattno == SelfItemPointerAttributeNumber)
3338

3439
typedef enum
3540
{

src/backend/executor/nodeTidscan.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,16 @@
3535
#include "utils/rel.h"
3636

3737

38+
/*
39+
* It's sufficient to check varattno to identify the CTID variable, as any
40+
* Var in the relation scan qual must be for our table. (Even if it's a
41+
* parameterized scan referencing some other table's CTID, the other table's
42+
* Var would have become a Param by the time it gets here.)
43+
*/
3844
#define IsCTIDVar(node) \
3945
((node) != NULL && \
4046
IsA((node), Var) && \
41-
((Var *) (node))->varattno == SelfItemPointerAttributeNumber && \
42-
((Var *) (node))->varlevelsup == 0)
47+
((Var *) (node))->varattno == SelfItemPointerAttributeNumber)
4348

4449
/* one element in tss_tidexprs */
4550
typedef struct TidExpr

0 commit comments

Comments
 (0)