Hi,

Playing with a large value of partitions I caught the limit with 65000 table entries in a query plan:

if (IS_SPECIAL_VARNO(list_length(glob->finalrtable)))
        ereport(ERROR,
                (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
                errmsg("too many range table entries")));

Postgres works well with so many partitions.
The constants INNER_VAR, OUTER_VAR, INDEX_VAR are used as values of the variable 'var->varno' of integer type. As I see, they were introduced with commit 1054097464 authored by Marc G. Fournier, in 1996.
Value 65000 was relevant to the size of the int type at that time.

Maybe we will change these values to INT_MAX? (See the patch in attachment).

--
regards,
Andrey Lepikhov
Postgres Professional
From 98da77cdefd53dbf4ce0c740d1a0f356da970648 Mon Sep 17 00:00:00 2001
From: "Andrey V. Lepikhov" <a.lepik...@postgrespro.ru>
Date: Wed, 3 Mar 2021 11:22:32 +0300
Subject: [PATCH] Set values of special varnos to the upper bound of the int
 type

---
 src/include/nodes/primnodes.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/include/nodes/primnodes.h b/src/include/nodes/primnodes.h
index d4ce037088..9038d97886 100644
--- a/src/include/nodes/primnodes.h
+++ b/src/include/nodes/primnodes.h
@@ -168,9 +168,9 @@ typedef struct Expr
  * in the planner and doesn't correspond to any simple relation column may
  * have varnosyn = varattnosyn = 0.
  */
-#define    INNER_VAR           65000   /* reference to inner subplan */
-#define    OUTER_VAR           65001   /* reference to outer subplan */
-#define    INDEX_VAR           65002   /* reference to index column */
+#define    INNER_VAR           (INT_MAX - 2)   /* reference to inner subplan */
+#define    OUTER_VAR           (INT_MAX - 1)   /* reference to outer subplan */
+#define    INDEX_VAR           (INT_MAX)       /* reference to index column */
 
 #define IS_SPECIAL_VARNO(varno)                ((varno) >= INNER_VAR)
 
-- 
2.29.2

Reply via email to