Re: missing optimization - column <> column - Mailing list pgsql-hackers

From Tom Lane
Subject Re: missing optimization - column <> column
Date
Msg-id 32715.1480951462@sss.pgh.pa.us
Whole thread Raw
In response to missing optimization - column <> column  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: missing optimization - column <> column  (Pavel Stehule <pavel.stehule@gmail.com>)
Re: missing optimization - column <> column  (Pantelis Theodosiou <ypercube@gmail.com>)
List pgsql-hackers
Pavel Stehule <pavel.stehule@gmail.com> writes:
> I found some crazy queries in one customer application. These queries are
> stupid, but it was surprise for me so there are not some simple optimization

> create table foo(a int);
> insert into foo select generate_series(1,100000);
> analyze foo;
> explain select * from foo where a <> a;

> It does full scan of foo, although it should be replaced by false in
> planner time.

> Same issue is a expression a = a .. can be replaced by true

Wrong; those expressions yield NULL for NULL input.  You could perhaps
optimize them slightly into some form of is-null test, but it hardly
seems worth the planner cycles to check for.

If you write something like "1 <> 1", it will be folded.
        regards, tom lane



pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: [COMMITTERS] pgsql: Introduce dynamic shared memory areas.
Next
From: Stephen Frost
Date:
Subject: Re: missing optimization - column <> column