pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feedORDER/GROUP BY expression not found in targetlist
8+ messages / 5 participants
[nested] [flat]
* ORDER/GROUP BY expression not found in targetlist
@ 2016-05-26 02:12 Andres Freund <andres@anarazel.de>
0 siblings, 2 replies; 8+ messages in thread
From: Andres Freund @ 2016-05-26 02:12 UTC (permalink / raw)
To: pgsql-hackers; Tom Lane <tgl@sss.pgh.pa.us>
Hi,
trying to reproduce a performance problem I just found:
=# CREATE TABLE twocol(col01 int, col02 int);
=# SELECT DISTINCT col01, col02, col01 FROM twocol ;
ERROR: XX000: ORDER/GROUP BY expression not found in targetlist
LOCATION: get_sortgroupref_tle, tlist.c:341
which appears to be a 9.6 regression, presumable fallout from the path
restructuring.
Greetings,
Andres Freund
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: ORDER/GROUP BY expression not found in targetlist
@ 2016-05-26 02:57 Peter Geoghegan <pg@heroku.com>
parent: Andres Freund <andres@anarazel.de>
1 sibling, 1 reply; 8+ messages in thread
From: Peter Geoghegan @ 2016-05-26 02:57 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; +Cc: pgsql-hackers; Tom Lane <tgl@sss.pgh.pa.us>
On Wed, May 25, 2016 at 7:12 PM, Andres Freund <andres@anarazel.de> wrote:
>
> =# CREATE TABLE twocol(col01 int, col02 int);
> =# SELECT DISTINCT col01, col02, col01 FROM twocol ;
> ERROR: XX000: ORDER/GROUP BY expression not found in targetlist
> LOCATION: get_sortgroupref_tle, tlist.c:341
>
> which appears to be a 9.6 regression, presumable fallout from the path
> restructuring.
It's surprising that SQL Smith didn't catch something with such simple
steps to reproduce.
--
Peter Geoghegan
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: ORDER/GROUP BY expression not found in targetlist
@ 2016-05-26 14:07 Andreas Seltenreich <seltenreich@gmx.de>
parent: Peter Geoghegan <pg@heroku.com>
0 siblings, 1 reply; 8+ messages in thread
From: Andreas Seltenreich @ 2016-05-26 14:07 UTC (permalink / raw)
To: Peter Geoghegan <pg@heroku.com>; +Cc: Andres Freund <andres@anarazel.de>; pgsql-hackers; Tom Lane <tgl@sss.pgh.pa.us>
Peter Geoghegan writes:
> On Wed, May 25, 2016 at 7:12 PM, Andres Freund <andres@anarazel.de> wrote:
>>
>> =# CREATE TABLE twocol(col01 int, col02 int);
>> =# SELECT DISTINCT col01, col02, col01 FROM twocol ;
>> ERROR: XX000: ORDER/GROUP BY expression not found in targetlist
>> LOCATION: get_sortgroupref_tle, tlist.c:341
>>
>> which appears to be a 9.6 regression, presumable fallout from the path
>> restructuring.
>
> It's surprising that SQL Smith didn't catch something with such simple
> steps to reproduce.
I removed distinct relatively early because it causes a large part of
queries to fail due to it not finding an equality operator it likes. It
seems to be more picky about the equality operator than, say, joins.
I'm sure it has a good reason to do so?
regression=> select distinct f1 from path_tbl;
ERROR: could not identify an equality operator for type path
LINE 1: select distinct f1 from path_tbl;
regression=> \do =
-[ RECORD 38 ]-+----------------------------
Schema | pg_catalog
Name | =
Left arg type | path
Right arg type | path
Result type | boolean
Description | equal
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: ORDER/GROUP BY expression not found in targetlist
@ 2016-05-26 14:12 Tom Lane <tgl@sss.pgh.pa.us>
parent: Andreas Seltenreich <seltenreich@gmx.de>
0 siblings, 1 reply; 8+ messages in thread
From: Tom Lane @ 2016-05-26 14:12 UTC (permalink / raw)
To: Andreas Seltenreich <seltenreich@gmx.de>; +Cc: Peter Geoghegan <pg@heroku.com>; Andres Freund <andres@anarazel.de>; pgsql-hackers
Andreas Seltenreich <seltenreich@gmx.de> writes:
> Peter Geoghegan writes:
>> It's surprising that SQL Smith didn't catch something with such simple
>> steps to reproduce.
> I removed distinct relatively early because it causes a large part of
> queries to fail due to it not finding an equality operator it likes. It
> seems to be more picky about the equality operator than, say, joins.
> I'm sure it has a good reason to do so?
It's looking for an operator that is known to be semantically equality,
by virtue of being the equality member of a btree or hash opclass.
Type path has no such opclass unfortunately. But when you write "a = b"
that just looks for an operator named "=".
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: ORDER/GROUP BY expression not found in targetlist
@ 2016-05-26 14:34 Andreas Seltenreich <seltenreich@gmx.de>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 8+ messages in thread
From: Andreas Seltenreich @ 2016-05-26 14:34 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Peter Geoghegan <pg@heroku.com>; Andres Freund <andres@anarazel.de>; pgsql-hackers
Tom Lane writes:
> Andreas Seltenreich <seltenreich@gmx.de> writes:
>> Peter Geoghegan writes:
>>> It's surprising that SQL Smith didn't catch something with such simple
>>> steps to reproduce.
>
>> I removed distinct relatively early because it causes a large part of
>> queries to fail due to it not finding an equality operator it likes. It
>> seems to be more picky about the equality operator than, say, joins.
>> I'm sure it has a good reason to do so?
>
> It's looking for an operator that is known to be semantically equality,
> by virtue of being the equality member of a btree or hash opclass.
> Type path has no such opclass unfortunately.
As do lots of data types in the regression db while still having an
operator providing semantic equivalence. I was hoping for someone to
question that status quo. Naively I'd say an equivalence flag is
missing in the catalog that is independent of opclasses.
regards
Andreas
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: ORDER/GROUP BY expression not found in targetlist
@ 2016-05-26 15:11 Tom Lane <tgl@sss.pgh.pa.us>
parent: Andreas Seltenreich <seltenreich@gmx.de>
0 siblings, 0 replies; 8+ messages in thread
From: Tom Lane @ 2016-05-26 15:11 UTC (permalink / raw)
To: Andreas Seltenreich <seltenreich@gmx.de>; +Cc: Peter Geoghegan <pg@heroku.com>; Andres Freund <andres@anarazel.de>; pgsql-hackers
Andreas Seltenreich <seltenreich@gmx.de> writes:
> Tom Lane writes:
>> It's looking for an operator that is known to be semantically equality,
>> by virtue of being the equality member of a btree or hash opclass.
>> Type path has no such opclass unfortunately.
> As do lots of data types in the regression db while still having an
> operator providing semantic equivalence. I was hoping for someone to
> question that status quo. Naively I'd say an equivalence flag is
> missing in the catalog that is independent of opclasses.
[ shrug... ] I see little wrong with that status quo. For this
particular use-case, there are two ways we could implement DISTINCT: one
of them requires sorting, and the other requires hashing. So you would
need to provide that opclass infrastructure even if there were some other
way of identifying the operator that means equality.
Type path and the other geometric types lack any natural sort order so
it's hard to imagine making a default btree opclass for them. But a
default hash opclass might not be out of reach, given an exact equality
operator.
Another problem with the geometric types is that long ago somebody
invented "=" operators for most of them that have little to do with what
anyone would consider equality. The "path = path" operator just compares
whether the paths have the same number of points. A lot of the other ones
compare areas. It'd be hard to justify marking any of them as default
equality for the type.
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: ORDER/GROUP BY expression not found in targetlist
@ 2016-05-26 17:22 Tom Lane <tgl@sss.pgh.pa.us>
parent: Andres Freund <andres@anarazel.de>
1 sibling, 1 reply; 8+ messages in thread
From: Tom Lane @ 2016-05-26 17:22 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; +Cc: pgsql-hackers
Andres Freund <andres@anarazel.de> writes:
> trying to reproduce a performance problem I just found:
> =# CREATE TABLE twocol(col01 int, col02 int);
> =# SELECT DISTINCT col01, col02, col01 FROM twocol ;
> ERROR: XX000: ORDER/GROUP BY expression not found in targetlist
> LOCATION: get_sortgroupref_tle, tlist.c:341
> which appears to be a 9.6 regression, presumable fallout from the path
> restructuring.
Huh. The problem is that createplan.c is trying to apply the
physical-tlist optimization to the seqscan underneath the aggregate
node. That means that the output from the seqscan is just
"col01, col02", which means that col01 can only be decorated with
a single ressortgroupref ... but there are two ressortgrouprefs
for it as far as the groupClause is concerned. Only one gets applied
to the seqscan's tlist, and then later we fail because we don't find
the other one there. Conclusions:
* we need to back off the physical-tlist optimization in this case
* the code that transfers sortgroupref labels onto a tlist probably
ought to notice and complain if it's asked to put inconsistent labels
onto the same column.
I'm a little surprised that it's not discarding the third grouping
item as redundant ... but that's probably not something to mess with
right now. Prior versions don't appear to do that either.
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: ORDER/GROUP BY expression not found in targetlist
@ 2016-06-09 03:08 Tatsuro Yamada <yamada.tatsuro@lab.ntt.co.jp>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 8+ messages in thread
From: Tatsuro Yamada @ 2016-06-09 03:08 UTC (permalink / raw)
To: pgsql-hackers
Hi,
I got same error by TPC-H: Q1,4,8,12 and 17.
I've attached results of the queries.
TPC-H (thanks to Tomas Vondra)
https://github.com/tvondra/pg_tpch
Datasize
Scale Factor: 1
PG96beta1
commit: f721e94b5f360391fc3ffe183bf697a0441e9184
Regards,
Tatsuro Yamada
NTT OSS Center
On 2016/05/27 2:22, Tom Lane wrote:
> Andres Freund <andres@anarazel.de> writes:
>> trying to reproduce a performance problem I just found:
>
>> =# CREATE TABLE twocol(col01 int, col02 int);
>> =# SELECT DISTINCT col01, col02, col01 FROM twocol ;
>> ERROR: XX000: ORDER/GROUP BY expression not found in targetlist
>> LOCATION: get_sortgroupref_tle, tlist.c:341
>
>> which appears to be a 9.6 regression, presumable fallout from the path
>> restructuring.
>
> Huh. The problem is that createplan.c is trying to apply the
> physical-tlist optimization to the seqscan underneath the aggregate
> node. That means that the output from the seqscan is just
> "col01, col02", which means that col01 can only be decorated with
> a single ressortgroupref ... but there are two ressortgrouprefs
> for it as far as the groupClause is concerned. Only one gets applied
> to the seqscan's tlist, and then later we fail because we don't find
> the other one there. Conclusions:
>
> * we need to back off the physical-tlist optimization in this case
>
> * the code that transfers sortgroupref labels onto a tlist probably
> ought to notice and complain if it's asked to put inconsistent labels
> onto the same column.
>
> I'm a little surprised that it's not discarding the third grouping
> item as redundant ... but that's probably not something to mess with
> right now. Prior versions don't appear to do that either.
>
> regards, tom lane
>
>
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Attachments:
order_groupby_error.txt (text/plain, 5.7K) download
commit f721e94b5f360391fc3ffe183bf697a0441e9184
[postgres@bluey queries]$ psql
psql (9.6beta1)
Type "help" for help.
postgres=# \i 1.explain.sql
ERROR: ORDER/GROUP BY expression not found in targetlist
STATEMENT: explain analyze select
l_returnflag,
l_linestatus,
sum(l_quantity) as sum_qty,
sum(l_extendedprice) as sum_base_price,
sum(l_extendedprice * (1 - l_discount)) as sum_disc_price,
sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge,
avg(l_quantity) as avg_qty,
avg(l_extendedprice) as avg_price,
avg(l_discount) as avg_disc,
count(*) as count_order
from
lineitem
where
l_shipdate <= date '1998-12-01' - interval '70' day
group by
l_returnflag,
l_linestatus
order by
l_returnflag,
l_linestatus
LIMIT 1;
postgres=# \i 4.explain.sql
ERROR: ORDER/GROUP BY expression not found in targetlist
STATEMENT: explain analyze select
o_orderpriority,
count(*) as order_count
from
orders
where
o_orderdate >= date '1993-10-01'
and o_orderdate < date '1993-10-01' + interval '3' month
and exists (
select
*
from
lineitem
where
l_orderkey = o_orderkey
and l_commitdate < l_receiptdate
)
group by
o_orderpriority
order by
o_orderpriority
LIMIT 1;
postgres=# \i 8.explain.sql
ERROR: ORDER/GROUP BY expression not found in targetlist
STATEMENT: explain analyze select
o_year,
sum(case
when nation = 'EGYPT' then volume
else 0
end) / sum(volume) as mkt_share
from
(
select
extract(year from o_orderdate) as o_year,
l_extendedprice * (1 - l_discount) as volume,
n2.n_name as nation
from
part,
supplier,
lineitem,
orders,
customer,
nation n1,
nation n2,
region
where
p_partkey = l_partkey
and s_suppkey = l_suppkey
and l_orderkey = o_orderkey
and o_custkey = c_custkey
and c_nationkey = n1.n_nationkey
and n1.n_regionkey = r_regionkey
and r_name = 'MIDDLE EAST'
and s_nationkey = n2.n_nationkey
and o_orderdate between date '1995-01-01' and date '1996-12-31'
and p_type = 'STANDARD ANODIZED TIN'
) as all_nations
group by
o_year
order by
o_year
LIMIT 1;
postgres=# \i 12.explain.sql
ERROR: ORDER/GROUP BY expression not found in targetlist
STATEMENT: explain analyze select
l_shipmode,
sum(case
when o_orderpriority = '1-URGENT'
or o_orderpriority = '2-HIGH'
then 1
else 0
end) as high_line_count,
sum(case
when o_orderpriority <> '1-URGENT'
and o_orderpriority <> '2-HIGH'
then 1
else 0
end) as low_line_count
from
orders,
lineitem
where
o_orderkey = l_orderkey
and l_shipmode in ('REG AIR', 'AIR')
and l_commitdate < l_receiptdate
and l_shipdate < l_commitdate
and l_receiptdate >= date '1996-01-01'
and l_receiptdate < date '1996-01-01' + interval '1' year
group by
l_shipmode
order by
l_shipmode
LIMIT 1;
postgres=# \i 17.explain.sql
ERROR: ORDER/GROUP BY expression not found in targetlist
STATEMENT: explain analyze select
sum(l_extendedprice) / 7.0 as avg_yearly
from
lineitem,
part,
(SELECT l_partkey AS agg_partkey, 0.2 * avg(l_quantity) AS avg_quantity FROM lineitem GROUP BY l_partkey) part_agg
where
p_partkey = l_partkey
and agg_partkey = l_partkey
and p_brand = 'Brand#44'
and p_container = 'MED PACK'
and l_quantity < avg_quantity
LIMIT 1;
---------------------------------------------
BTW, Andres's query is OK.
postgres=# CREATE TABLE twocol(col01 int, col02 int);
CREATE TABLE
postgres=# SELECT DISTINCT col01, col02, col01 FROM twocol ;
col01 | col02 | col01
-------+-------+-------
(0 rows)
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2016-06-09 03:08 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-05-26 02:12 ORDER/GROUP BY expression not found in targetlist Andres Freund <andres@anarazel.de>
2016-05-26 02:57 ` Peter Geoghegan <pg@heroku.com>
2016-05-26 14:07 ` Andreas Seltenreich <seltenreich@gmx.de>
2016-05-26 14:12 ` Tom Lane <tgl@sss.pgh.pa.us>
2016-05-26 14:34 ` Andreas Seltenreich <seltenreich@gmx.de>
2016-05-26 15:11 ` Tom Lane <tgl@sss.pgh.pa.us>
2016-05-26 17:22 ` Tom Lane <tgl@sss.pgh.pa.us>
2016-06-09 03:08 ` Tatsuro Yamada <yamada.tatsuro@lab.ntt.co.jp>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox