BUG #17476: ERROR: "variable not found in subplan target list" when running SELECT COUNT(*)

Lists: pgsql-bugs
From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: milos(dot)urbanek(at)email(dot)cz
Subject: BUG #17476: ERROR: "variable not found in subplan target list" when running SELECT COUNT(*)
Date: 2022-05-08 22:11:03
Message-ID: 17476-cf579fc6b204baa2@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 17476
Logged by: Milos Urbanek
Email address: milos(dot)urbanek(at)email(dot)cz
PostgreSQL version: 14.2
Operating system: Windows 2012 R2 Foundation
Description:

Trying to run simple SELECT COUNT(*) from some table gives me the following
error (either running by hand or trying to run EXPLAIN using pgadmin or by
hand):

2022-05-09 00:06:30.428 CEST [1196] ERROR: variable not found in subplan
target list
2022-05-09 00:06:30.428 CEST [1196] STATEMENT: SELECT COUNT(*) FROM
"domino_efekty_havarijniprojev"
2022-05-09 00:06:31.884 CEST [1196] ERROR: variable not found in subplan
target list
2022-05-09 00:06:31.884 CEST [1196] STATEMENT: EXPLAIN (FORMAT JSON,
ANALYZE false, VERBOSE false, COSTS false, TIMING false, BUFFERS false,
SUMMARY false, SETTINGS false) SELECT COUNT(*) FROM
"domino_efekty_havarijniprojev"
2022-05-09 00:06:39.820 CEST [1196] ERROR: variable not found in subplan
target list
2022-05-09 00:06:39.820 CEST [1196] STATEMENT: EXPLAIN SELECT COUNT(*) FROM
"domino_efekty_havarijniprojev"

Differences against standard config:
shared_buffers = 8192MB
effective_cache_size = 16GB
cursor_tuple_fraction = 1.0


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: milos(dot)urbanek(at)email(dot)cz
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #17476: ERROR: "variable not found in subplan target list" when running SELECT COUNT(*)
Date: 2022-05-09 00:22:01
Message-ID: 3488097.1652055721@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> Trying to run simple SELECT COUNT(*) from some table gives me the following
> error (either running by hand or trying to run EXPLAIN using pgadmin or by
> hand):

> 2022-05-09 00:06:30.428 CEST [1196] ERROR: variable not found in subplan
> target list
> 2022-05-09 00:06:30.428 CEST [1196] STATEMENT: SELECT COUNT(*) FROM
> "domino_efekty_havarijniprojev"

Is that really just a table? I could believe a bug like this for
some types of views, but it's a bit hard to credit for a plain table.

In any case, we can't do much with this report unless you can provide
a reproducer case --- preferably a SQL script that creates an object
that triggers the problem.

regards, tom lane


From: Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #17476: ERROR: "variable not found in subplan target list" when running SELECT COUNT(*)
Date: 2022-05-09 07:21:56
Message-ID: 5wS.wBLd.2GdiEutIVdh.1YUC4K@scif.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs


I have 2 (ordinary) tables in 900+ table database restored from PG 9.6 (with
PostGIS geometries BTW) where this problem occurs.

The count() queries into the other tables are OK.

Also the problem happens only at the server but not at my Windows 10
workstation with the same PG 14.2.

No clue what could be wrong.

PGAdmin4 fails even when trying to list SQL creation statement.

--

Milos Urbanek

---------- Původní e-mail ----------
Od: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Komu: milos(dot)urbanek(at)email(dot)cz
Datum: 9. 5. 2022 2:22:10
Předmět: Re: BUG #17476: ERROR: "variable not found in subplan target list"
when running SELECT COUNT(*)
"PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> Trying to run simple SELECT COUNT(*) from some table gives me the
following
> error (either running by hand or trying to run EXPLAIN using pgadmin or by

> hand):

> 2022-05-09 00:06:30.428 CEST [1196] ERROR: variable not found in subplan
> target list
> 2022-05-09 00:06:30.428 CEST [1196] STATEMENT: SELECT COUNT(*) FROM
> "domino_efekty_havarijniprojev"

Is that really just a table? I could believe a bug like this for
some types of views, but it's a bit hard to credit for a plain table.

In any case, we can't do much with this report unless you can provide
a reproducer case --- preferably a SQL script that creates an object
that triggers the problem.

regards, tom lane
"


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #17476: ERROR: "variable not found in subplan target list" when running SELECT COUNT(*)
Date: 2022-05-09 08:21:33
Message-ID: CAFj8pRCmTZHid9CzwK55ehx33M5VcbY+b5sWDYwC844R27u76g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Hi

po 9. 5. 2022 v 9:22 odesílatel Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz>
napsal:

> I have 2 (ordinary) tables in 900+ table database restored from PG 9.6
> (with PostGIS geometries BTW) where this problem occurs.
> The count() queries into the other tables are OK.
> Also the problem happens only at the server but not at my Windows 10
> workstation with the same PG 14.2.
>

Is there the same configuration on the server like on your workstation?
The different configuration can enforce a different execution plan.

Regards

Pavel

No clue what could be wrong.
>
> PGAdmin4 fails even when trying to list SQL creation statement.
>
> --
> Milos Urbanek
>
> ---------- Původní e-mail ----------
> Od: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
> Komu: milos(dot)urbanek(at)email(dot)cz
> Datum: 9. 5. 2022 2:22:10
> Předmět: Re: BUG #17476: ERROR: "variable not found in subplan target
> list" when running SELECT COUNT(*)
>
> PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> > Trying to run simple SELECT COUNT(*) from some table gives me the
> following
> > error (either running by hand or trying to run EXPLAIN using pgadmin or
> by
> > hand):
>
> > 2022-05-09 00:06:30.428 CEST [1196] ERROR: variable not found in subplan
> > target list
> > 2022-05-09 00:06:30.428 CEST [1196] STATEMENT: SELECT COUNT(*) FROM
> > "domino_efekty_havarijniprojev"
>
> Is that really just a table? I could believe a bug like this for
> some types of views, but it's a bit hard to credit for a plain table.
>
> In any case, we can't do much with this report unless you can provide
> a reproducer case --- preferably a SQL script that creates an object
> that triggers the problem.
>
> regards, tom lane
>
>


From: Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz>
To: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "PostgreSQL mailing lists" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #17476: ERROR: "variable not found in subplan target list" when running SELECT COUNT(*)
Date: 2022-05-09 08:35:33
Message-ID: 609.wBLt.62HW}58GAL}.1YUD9L@scif.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs


Difference in shared_buffers (1GB) and effective_cache_size (default) only.

When I delete all data from the table, SELECT count(*) works..

--

Miloš Urbánek

tel.: 736 608 345

---------- Původní e-mail ----------
Od: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Komu: Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz>
Datum: 9. 5. 2022 10:22:16
Předmět: Re: BUG #17476: ERROR: "variable not found in subplan target list"
when running SELECT COUNT(*)
"

Hi

po 9. 5. 2022 v 9:22 odesílatel Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz
(mailto:milos(dot)urbanek(at)email(dot)cz)> napsal:

"

I have 2 (ordinary) tables in 900+ table database restored from PG 9.6 (with
PostGIS geometries BTW) where this problem occurs.

The count() queries into the other tables are OK.

Also the problem happens only at the server but not at my Windows 10
workstation with the same PG 14.2.

"

Is there the same configuration on the server like on your workstation?  The
different configuration can enforce a different execution plan.

Regards

Pavel

"

No clue what could be wrong.

PGAdmin4 fails even when trying to list SQL creation statement.

--

Milos Urbanek

---------- Původní e-mail ----------
Od: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us(mailto:tgl(at)sss(dot)pgh(dot)pa(dot)us)>
Komu: milos(dot)urbanek(at)email(dot)cz(mailto:milos(dot)urbanek(at)email(dot)cz)
Datum: 9. 5. 2022 2:22:10
Předmět: Re: BUG #17476: ERROR: "variable not found in subplan target list"
when running SELECT COUNT(*)
"PG Bug reporting form <noreply(at)postgresql(dot)org
(mailto:noreply(at)postgresql(dot)org)> writes:
> Trying to run simple SELECT COUNT(*) from some table gives me the
following
> error (either running by hand or trying to run EXPLAIN using pgadmin or by

> hand):

> 2022-05-09 00:06:30.428 CEST [1196] ERROR: variable not found in subplan
> target list
> 2022-05-09 00:06:30.428 CEST [1196] STATEMENT: SELECT COUNT(*) FROM
> "domino_efekty_havarijniprojev"

Is that really just a table? I could believe a bug like this for
some types of views, but it's a bit hard to credit for a plain table.

In any case, we can't do much with this report unless you can provide
a reproducer case --- preferably a SQL script that creates an object
that triggers the problem.

regards, tom lane
"
"

"


From: Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz>
To: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "PostgreSQL mailing lists" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #17476: ERROR: "variable not found in subplan target list" when running SELECT COUNT(*)
Date: 2022-05-09 08:39:11
Message-ID: 60O.wBLp.14yuVyE8P3I.1YUDCl@scif.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs


I actually pray that my issue is just this one:

https://www.mail-archive.com/postgis-users(at)lists(dot)osgeo(dot)org/msg09410.html

--

Milosh

---------- Původní e-mail ----------
Od: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Komu: Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz>
Datum: 9. 5. 2022 10:22:16
Předmět: Re: BUG #17476: ERROR: "variable not found in subplan target list"
when running SELECT COUNT(*)
"

Hi

po 9. 5. 2022 v 9:22 odesílatel Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz
(mailto:milos(dot)urbanek(at)email(dot)cz)> napsal:

"

I have 2 (ordinary) tables in 900+ table database restored from PG 9.6 (with
PostGIS geometries BTW) where this problem occurs.

The count() queries into the other tables are OK.

Also the problem happens only at the server but not at my Windows 10
workstation with the same PG 14.2.

"

Is there the same configuration on the server like on your workstation?  The
different configuration can enforce a different execution plan.

Regards

Pavel

"

No clue what could be wrong.

PGAdmin4 fails even when trying to list SQL creation statement.

--

Milos Urbanek

---------- Původní e-mail ----------
Od: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us(mailto:tgl(at)sss(dot)pgh(dot)pa(dot)us)>
Komu: milos(dot)urbanek(at)email(dot)cz(mailto:milos(dot)urbanek(at)email(dot)cz)
Datum: 9. 5. 2022 2:22:10
Předmět: Re: BUG #17476: ERROR: "variable not found in subplan target list"
when running SELECT COUNT(*)
"PG Bug reporting form <noreply(at)postgresql(dot)org
(mailto:noreply(at)postgresql(dot)org)> writes:
> Trying to run simple SELECT COUNT(*) from some table gives me the
following
> error (either running by hand or trying to run EXPLAIN using pgadmin or by

> hand):

> 2022-05-09 00:06:30.428 CEST [1196] ERROR: variable not found in subplan
> target list
> 2022-05-09 00:06:30.428 CEST [1196] STATEMENT: SELECT COUNT(*) FROM
> "domino_efekty_havarijniprojev"

Is that really just a table? I could believe a bug like this for
some types of views, but it's a bit hard to credit for a plain table.

In any case, we can't do much with this report unless you can provide
a reproducer case --- preferably a SQL script that creates an object
that triggers the problem.

regards, tom lane
"
"

"


From: Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz>
To: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "PostgreSQL mailing lists" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #17476: ERROR: "variable not found in subplan target list" when running SELECT COUNT(*)
Date: 2022-05-09 08:52:47
Message-ID: 61T.wBL}.7P5DeHGHwts.1YUDPV@scif.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs


The problem occurs in test database restored from PG 14 backup. There are 2
tables (out of 900 other) where this problem occurs (when running SELECT
COUNT(*) on the table).

I can not look at the query plan because EXPLAIN fails aswell, but my guess
is that planner is trying to use index on the table to count the rows.

There are only 10 records in the table. When I run VACUUM FULL, the problem
disappears (planner is going to use Seq Scan which works).

The database schema for both tables is complex, there are 20+ columns, 3+
spatial data columns, 5 foreign keys, not such an easy task to create some
test case for you.

But my guess is that the root cause is planner trying to use index scan to
count the rows.

Therefore I hope that this is just another occurence of https://www.mail-
archive.com/postgis-users(at)lists(dot)osgeo(dot)org/msg09410.html.

Regards

--

Milosh

---------- Původní e-mail ----------
Od: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Komu: Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz>
Datum: 9. 5. 2022 10:22:16
Předmět: Re: BUG #17476: ERROR: "variable not found in subplan target list"
when running SELECT COUNT(*)
"

Hi

po 9. 5. 2022 v 9:22 odesílatel Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz
(mailto:milos(dot)urbanek(at)email(dot)cz)> napsal:

"

I have 2 (ordinary) tables in 900+ table database restored from PG 9.6 (with
PostGIS geometries BTW) where this problem occurs.

The count() queries into the other tables are OK.

Also the problem happens only at the server but not at my Windows 10
workstation with the same PG 14.2.

"

Is there the same configuration on the server like on your workstation?  The
different configuration can enforce a different execution plan.

Regards

Pavel

"

No clue what could be wrong.

PGAdmin4 fails even when trying to list SQL creation statement.

--

Milos Urbanek

---------- Původní e-mail ----------
Od: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us(mailto:tgl(at)sss(dot)pgh(dot)pa(dot)us)>
Komu: milos(dot)urbanek(at)email(dot)cz(mailto:milos(dot)urbanek(at)email(dot)cz)
Datum: 9. 5. 2022 2:22:10
Předmět: Re: BUG #17476: ERROR: "variable not found in subplan target list"
when running SELECT COUNT(*)
"PG Bug reporting form <noreply(at)postgresql(dot)org
(mailto:noreply(at)postgresql(dot)org)> writes:
> Trying to run simple SELECT COUNT(*) from some table gives me the
following
> error (either running by hand or trying to run EXPLAIN using pgadmin or by

> hand):

> 2022-05-09 00:06:30.428 CEST [1196] ERROR: variable not found in subplan
> target list
> 2022-05-09 00:06:30.428 CEST [1196] STATEMENT: SELECT COUNT(*) FROM
> "domino_efekty_havarijniprojev"

Is that really just a table? I could believe a bug like this for
some types of views, but it's a bit hard to credit for a plain table.

In any case, we can't do much with this report unless you can provide
a reproducer case --- preferably a SQL script that creates an object
that triggers the problem.

regards, tom lane
"
"

"


From: Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #17476: ERROR: "variable not found in subplan target list" when running SELECT COUNT(*)
Date: 2022-05-09 08:59:06
Message-ID: 620.wBLx.mpsJ89z3rK.1YUDVQ@scif.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs


When I set:

enable_bitmapscan = off
enable_seqscan = off

I can reproduce the problem. The table has 42 columns. Seems like https://
www.postgresql.org/message-id/2121219.1644607692%40sss.pgh.pa.us

I will wait for 9.3 and give it a try.

--

Milosh

---------- Původní e-mail ----------
Od: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Komu: milos(dot)urbanek(at)email(dot)cz
Datum: 9. 5. 2022 2:22:10
Předmět: Re: BUG #17476: ERROR: "variable not found in subplan target list"
when running SELECT COUNT(*)
"PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> Trying to run simple SELECT COUNT(*) from some table gives me the
following
> error (either running by hand or trying to run EXPLAIN using pgadmin or by

> hand):

> 2022-05-09 00:06:30.428 CEST [1196] ERROR: variable not found in subplan
> target list
> 2022-05-09 00:06:30.428 CEST [1196] STATEMENT: SELECT COUNT(*) FROM
> "domino_efekty_havarijniprojev"

Is that really just a table? I could believe a bug like this for
some types of views, but it's a bit hard to credit for a plain table.

In any case, we can't do much with this report unless you can provide
a reproducer case --- preferably a SQL script that creates an object
that triggers the problem.

regards, tom lane
"


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #17476: ERROR: "variable not found in subplan target list" when running SELECT COUNT(*)
Date: 2022-05-09 09:50:18
Message-ID: CAFj8pRBDyPCsnzq6yKNvsRiifpuV8=seMNku8u+bx9vWX05d8A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

po 9. 5. 2022 v 10:52 odesílatel Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz>
napsal:

> The problem occurs in test database restored from PG 14 backup. There are
> 2 tables (out of 900 other) where this problem occurs (when running SELECT
> COUNT(*) on the table).
>
> I can not look at the query plan because EXPLAIN fails aswell, but my
> guess is that planner is trying to use index on the table to count the rows.
>
> There are only 10 records in the table. When I run VACUUM FULL, the
> problem disappears (planner is going to use Seq Scan which works).
>

Did you run ANALYZE?

Regads

Pavel

>
> The database schema for both tables is complex, there are 20+ columns, 3+
> spatial data columns, 5 foreign keys, not such an easy task to create some
> test case for you.
>
> But my guess is that the root cause is planner trying to use index scan to
> count the rows.
>
> Therefore I hope that this is just another occurence of
> https://www.mail-archive.com/postgis-users(at)lists(dot)osgeo(dot)org/msg09410.html.
>
> Regards
>
> --
> Milosh
>
> ---------- Původní e-mail ----------
> Od: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> Komu: Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz>
> Datum: 9. 5. 2022 10:22:16
> Předmět: Re: BUG #17476: ERROR: "variable not found in subplan target
> list" when running SELECT COUNT(*)
>
> Hi
>
> po 9. 5. 2022 v 9:22 odesílatel Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz>
> napsal:
>
> I have 2 (ordinary) tables in 900+ table database restored from PG 9.6
> (with PostGIS geometries BTW) where this problem occurs.
> The count() queries into the other tables are OK.
> Also the problem happens only at the server but not at my Windows 10
> workstation with the same PG 14.2.
>
>
> Is there the same configuration on the server like on your workstation?
> The different configuration can enforce a different execution plan.
>
> Regards
>
> Pavel
>
>
> No clue what could be wrong.
>
> PGAdmin4 fails even when trying to list SQL creation statement.
>
> --
> Milos Urbanek
>
> ---------- Původní e-mail ----------
> Od: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
> Komu: milos(dot)urbanek(at)email(dot)cz
> Datum: 9. 5. 2022 2:22:10
> Předmět: Re: BUG #17476: ERROR: "variable not found in subplan target
> list" when running SELECT COUNT(*)
>
> PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> > Trying to run simple SELECT COUNT(*) from some table gives me the
> following
> > error (either running by hand or trying to run EXPLAIN using pgadmin or
> by
> > hand):
>
> > 2022-05-09 00:06:30.428 CEST [1196] ERROR: variable not found in subplan
> > target list
> > 2022-05-09 00:06:30.428 CEST [1196] STATEMENT: SELECT COUNT(*) FROM
> > "domino_efekty_havarijniprojev"
>
> Is that really just a table? I could believe a bug like this for
> some types of views, but it's a bit hard to credit for a plain table.
>
> In any case, we can't do much with this report unless you can provide
> a reproducer case --- preferably a SQL script that creates an object
> that triggers the problem.
>
> regards, tom lane
>
>


From: Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz>
To: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "PostgreSQL mailing lists" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #17476: ERROR: "variable not found in subplan target list" when running SELECT COUNT(*)
Date: 2022-05-09 10:02:37
Message-ID: 27.wBLD.1Y3Kkn9D3f4.1YUEQz@scif.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

No. But it would probably work as workaround aswell.

--

Milosh

---------- Původní e-mail ----------
Od: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Komu: Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz>
Datum: 9. 5. 2022 11:51:05
Předmět: Re: BUG #17476: ERROR: "variable not found in subplan target list"
when running SELECT COUNT(*)
"

po 9. 5. 2022 v 10:52 odesílatel Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz
(mailto:milos(dot)urbanek(at)email(dot)cz)> napsal:

"

The problem occurs in test database restored from PG 14 backup. There are 2
tables (out of 900 other) where this problem occurs (when running SELECT
COUNT(*) on the table).

I can not look at the query plan because EXPLAIN fails aswell, but my guess
is that planner is trying to use index on the table to count the rows.

There are only 10 records in the table. When I run VACUUM FULL, the problem
disappears (planner is going to use Seq Scan which works).

"

Did you run ANALYZE?

Regads

Pavel

 

"

The database schema for both tables is complex, there are 20+ columns, 3+
spatial data columns, 5 foreign keys, not such an easy task to create some
test case for you.

But my guess is that the root cause is planner trying to use index scan to
count the rows.

Therefore I hope that this is just another occurence of https://www.mail-
archive.com/postgis-users(at)lists(dot)osgeo(dot)org/msg09410.html
(https://www.mail-archive.com/postgis-users(at)lists(dot)osgeo(dot)org/msg09410.html)

Regards

--

Milosh

---------- Původní e-mail ----------
Od: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com(mailto:pavel(dot)stehule(at)gmail(dot)com)>
Komu: Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz(mailto:milos(dot)urbanek(at)email(dot)cz)>
Datum: 9. 5. 2022 10:22:16
Předmět: Re: BUG #17476: ERROR: "variable not found in subplan target list"
when running SELECT COUNT(*)
"

Hi

po 9. 5. 2022 v 9:22 odesílatel Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz
(mailto:milos(dot)urbanek(at)email(dot)cz)> napsal:

"

I have 2 (ordinary) tables in 900+ table database restored from PG 9.6 (with
PostGIS geometries BTW) where this problem occurs.

The count() queries into the other tables are OK.

Also the problem happens only at the server but not at my Windows 10
workstation with the same PG 14.2.

"

Is there the same configuration on the server like on your workstation?  The
different configuration can enforce a different execution plan.

Regards

Pavel

"

No clue what could be wrong.

PGAdmin4 fails even when trying to list SQL creation statement.

--

Milos Urbanek

---------- Původní e-mail ----------
Od: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us(mailto:tgl(at)sss(dot)pgh(dot)pa(dot)us)>
Komu: milos(dot)urbanek(at)email(dot)cz(mailto:milos(dot)urbanek(at)email(dot)cz)
Datum: 9. 5. 2022 2:22:10
Předmět: Re: BUG #17476: ERROR: "variable not found in subplan target list"
when running SELECT COUNT(*)
"PG Bug reporting form <noreply(at)postgresql(dot)org
(mailto:noreply(at)postgresql(dot)org)> writes:
> Trying to run simple SELECT COUNT(*) from some table gives me the
following
> error (either running by hand or trying to run EXPLAIN using pgadmin or by

> hand):

> 2022-05-09 00:06:30.428 CEST [1196] ERROR: variable not found in subplan
> target list
> 2022-05-09 00:06:30.428 CEST [1196] STATEMENT: SELECT COUNT(*) FROM
> "domino_efekty_havarijniprojev"

Is that really just a table? I could believe a bug like this for
some types of views, but it's a bit hard to credit for a plain table.

In any case, we can't do much with this report unless you can provide
a reproducer case --- preferably a SQL script that creates an object
that triggers the problem.

regards, tom lane
"
"

"
"

"


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #17476: ERROR: "variable not found in subplan target list" when running SELECT COUNT(*)
Date: 2022-05-09 10:25:10
Message-ID: CAFj8pRDRoZGjqG2RNcd5L7qzL2HGauBEZGeHmSnr0NywBKxurw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

po 9. 5. 2022 v 12:02 odesílatel Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz>
napsal:

> No. But it would probably work as workaround aswell.
>

Diagnostics of every issue on Postgres should be started by ANALYZE. And
after any migration, restore, ... running ANALYZE is really part of best
practicies

Regards

Pavel

>
> --
> Milosh
>
> ---------- Původní e-mail ----------
> Od: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> Komu: Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz>
> Datum: 9. 5. 2022 11:51:05
> Předmět: Re: BUG #17476: ERROR: "variable not found in subplan target
> list" when running SELECT COUNT(*)
>
>
>
> po 9. 5. 2022 v 10:52 odesílatel Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz>
> napsal:
>
> The problem occurs in test database restored from PG 14 backup. There are
> 2 tables (out of 900 other) where this problem occurs (when running SELECT
> COUNT(*) on the table).
>
> I can not look at the query plan because EXPLAIN fails aswell, but my
> guess is that planner is trying to use index on the table to count the rows.
>
> There are only 10 records in the table. When I run VACUUM FULL, the
> problem disappears (planner is going to use Seq Scan which works).
>
>
> Did you run ANALYZE?
>
> Regads
>
> Pavel
>
>
>
> The database schema for both tables is complex, there are 20+ columns, 3+
> spatial data columns, 5 foreign keys, not such an easy task to create some
> test case for you.
>
> But my guess is that the root cause is planner trying to use index scan to
> count the rows.
>
> Therefore I hope that this is just another occurence of
> https://www.mail-archive.com/postgis-users(at)lists(dot)osgeo(dot)org/msg09410.html.
>
> Regards
>
> --
> Milosh
>
> ---------- Původní e-mail ----------
> Od: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> Komu: Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz>
> Datum: 9. 5. 2022 10:22:16
> Předmět: Re: BUG #17476: ERROR: "variable not found in subplan target
> list" when running SELECT COUNT(*)
>
> Hi
>
> po 9. 5. 2022 v 9:22 odesílatel Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz>
> napsal:
>
> I have 2 (ordinary) tables in 900+ table database restored from PG 9.6
> (with PostGIS geometries BTW) where this problem occurs.
> The count() queries into the other tables are OK.
> Also the problem happens only at the server but not at my Windows 10
> workstation with the same PG 14.2.
>
>
> Is there the same configuration on the server like on your workstation?
> The different configuration can enforce a different execution plan.
>
> Regards
>
> Pavel
>
>
> No clue what could be wrong.
>
> PGAdmin4 fails even when trying to list SQL creation statement.
>
> --
> Milos Urbanek
>
> ---------- Původní e-mail ----------
> Od: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
> Komu: milos(dot)urbanek(at)email(dot)cz
> Datum: 9. 5. 2022 2:22:10
> Předmět: Re: BUG #17476: ERROR: "variable not found in subplan target
> list" when running SELECT COUNT(*)
>
> PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> > Trying to run simple SELECT COUNT(*) from some table gives me the
> following
> > error (either running by hand or trying to run EXPLAIN using pgadmin or
> by
> > hand):
>
> > 2022-05-09 00:06:30.428 CEST [1196] ERROR: variable not found in subplan
> > target list
> > 2022-05-09 00:06:30.428 CEST [1196] STATEMENT: SELECT COUNT(*) FROM
> > "domino_efekty_havarijniprojev"
>
> Is that really just a table? I could believe a bug like this for
> some types of views, but it's a bit hard to credit for a plain table.
>
> In any case, we can't do much with this report unless you can provide
> a reproducer case --- preferably a SQL script that creates an object
> that triggers the problem.
>
> regards, tom lane
>
>


From: Miloš Urbánek <milos(dot)urbanek(at)email(dot)cz>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #17476: ERROR: "variable not found in subplan target list" when running SELECT COUNT(*)
Date: 2022-05-09 23:26:17
Message-ID: d4.wBKh.7WBaDbIyNTm.1YUQCP@scif.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs


Hi,

the simplest script is something like:

create extension if not exists postgis;
CREATE TABLE IF NOT EXISTS public.table_with_geom
(
    id integer NOT NULL,
    geom geometry(Point,5514)
);
CREATE INDEX IF NOT EXISTS table_with_geom_id ON table_with_geom USING gist
(geom);
SET enable_seqscan = OFF;
SET enable_bitmapscan = OFF;
explain select count(*) from table_with_geom;

This should print:

NOTICE: extension "postgis" already exists, skipping ERROR: variable not
found in subplan target list SQL state: XX000

Regards

--

Milosh

---------- Původní e-mail ----------
Od: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Komu: milos(dot)urbanek(at)email(dot)cz
Datum: 9. 5. 2022 2:22:10
Předmět: Re: BUG #17476: ERROR: "variable not found in subplan target list"
when running SELECT COUNT(*)
"PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> Trying to run simple SELECT COUNT(*) from some table gives me the
following
> error (either running by hand or trying to run EXPLAIN using pgadmin or by

> hand):

> 2022-05-09 00:06:30.428 CEST [1196] ERROR: variable not found in subplan
> target list
> 2022-05-09 00:06:30.428 CEST [1196] STATEMENT: SELECT COUNT(*) FROM
> "domino_efekty_havarijniprojev"

Is that really just a table? I could believe a bug like this for
some types of views, but it's a bit hard to credit for a plain table.

In any case, we can't do much with this report unless you can provide
a reproducer case --- preferably a SQL script that creates an object
that triggers the problem.

regards, tom lane
"