Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cROe9-0003qA-Dc for pgsql-bugs@arkaria.postgresql.org; Wed, 11 Jan 2017 19:33:21 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cROe9-00054w-0k for pgsql-bugs@arkaria.postgresql.org; Wed, 11 Jan 2017 19:33:21 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cROdT-0003x3-Et for pgsql-bugs@postgresql.org; Wed, 11 Jan 2017 19:32:39 +0000 Received: from smtp-out.abv.bg ([194.153.145.80]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cROdP-0006FF-Na for pgsql-bugs@postgresql.org; Wed, 11 Jan 2017 19:32:38 +0000 Received: from nm33.abv.bg (nm33.ni.bg [192.168.151.4]) by smtp-out.abv.bg (Postfix) with ESMTP id D0F684EEB; Wed, 11 Jan 2017 21:32:31 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=abv.bg; s=smtp-out; t=1484163151; bh=Fobr9WUxh/XegWfj7GvUiPatD9BjHpFCCP4zHUlvCLg=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=Bx6gU7gMGLU3XaFFJhQ9lQUkmV4a4V4hIrqEgmM95WiMlh9ZdKOvJPyLTbF5qKP/b AWgv3UzP6u3AfdzYxra/ApMREj4XhtCNzuwbFS/DJPOp3vqFOQcak03L1Iup53a5RI bg9ROPX1RuuJKP6Xjg8+Ne5ZV7Ab3rjbyCeYD+Dg= Received: from nm33.abv.bg (localhost [127.0.0.1]) by nm33.abv.bg (Postfix) with ESMTP id BC3F212020F; Wed, 11 Jan 2017 21:32:31 +0200 (EET) Date: Wed, 11 Jan 2017 21:32:31 +0200 (EET) From: Stefan Stefanov To: Francisco Olarte Cc: "\"\"\"\"\"pgsql-bugs@postgresql.org\"\"\"\"\"" Message-ID: <550419838.46005.1484163151769.JavaMail.apache@nm33.abv.bg> In-Reply-To: References: <20170111131022.24286.18735@wrigleys.postgresql.org> Subject: Re: BUG #14491: Huge delay when specifying certain column names to select list expressions MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_46004_1373305228.1484163151748" X-Mailer: AbvMail 3.0 X-Originating-IP: 77.70.14.221 X-Pg-Spam-Score: -5.9 (-----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org ------=_Part_46004_1373305228.1484163151748 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Dear Francisco, team, Thanks, absolutely right. Please excuse my omission. Table field "data_in.ioground.tovaritelnica" is an index key. Therefore the first and third queries use it for 'order by' while the second does not since AS conceals the field name and the function call surely defeats the index. Sincerely, Stefan >-------- Оригинално писмо -------- >От: Francisco Olarte folarte@peoplecall.com >Относно: Re: [BUGS] BUG #14491: Huge delay when specifying certain column names to select list expressions >До: stefanov.sm@abv.bg >Изпратено на: 11.01.2017 17:39 On Wed, Jan 11, 2017 at 2:10 PM, stefanov.sm@abv.bg > wrote: > The following bug has been logged on the website: > This is a real life example - a simple function that makes text CP1251-safe > and 3 trivial queries. The first one is a test to determine whether the > function incurs significant performance penalty (it does not). Execution > time was 218 ms. > Having specified explicit names to the select list expressions (these names > are the same as the names of the underlying columns) execution time soared > to 9.1 sec. > The third query is the same as the second one except that the given > expression names are not the same as the names of the underlying columns. > The execution time was back again to the comfortable 219 ms. It seems to me your 1st and 3rd queries are the same, the 2nd is not, as order by uses the expresion, not the field, "tovaritelnica". ( https://www.postgresql.org/docs/9.2/static/sql-select.html#SQL-ORDERBY : "Each expression can be the name or ordinal number of an output column (SELECT list item), or it can be an arbitrary expression formed from input-column values." ) 1St: > SELECT ... Output column > data_in.clear_cp1251(tovaritelnica), ... > ORDER BY tovaritelnica DESC .. But ordered by field ( an expression ), as column is no named like it. 2Nd. > SELECT ... > data_in.clear_cp1251(tovaritelnica) AS tovaritelnica, ... > ORDER BY tovaritelnica DESC Now ordering by output column, it shadows the name. 3Rd: > SELECT ... > data_in.clear_cp1251(tovaritelnica) AS _tovaritelnica, .... > ORDER BY tovaritelnica DESC Again, ordering by expresion => field, no column. Try specifying the column name as "data_in.ioground.tovaritelnica" in the order by, or something similar. But remember 1st and 3rd query select one thing but order by a different one. Francisco Olarte. ------=_Part_46004_1373305228.1484163151748 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Dear Francisco, team,

Thanks, absolutely right. Please excuse my omi= ssion.
Table field "data_in.ioground.tovaritelnica" is an index key. Th= erefore the first and third queries use it for 'order by' while the second = does not since AS conceals the field name and the function call surely defe= ats the index.

Sincerely,=20 Stefan



>-------- =D0=9E=D1=80=D0=B8=D0=B3=D0=B8=D0=BD=D0=B0=D0=BB=D0=BD=D0=BE = =D0=BF=D0=B8=D1=81=D0=BC=D0=BE --------
>=D0=9E=D1=82: Francisco Olarte folarte@peoplecall.com
>=D0=9E=D1=82=D0=BD=D0=BE=D1=81=D0=BD=D0=BE: Re: [BUGS] BUG #14491:= Huge delay when specifying certain column names to select list expressions
>=D0=94=D0=BE: stefanov.sm@abv.bg
>=D0=98=D0=B7=D0=BF=D1=80=D0=B0=D1=82=D0=B5=D0=BD=D0=BE =D0=BD=D0= =B0: 11.01.2017 17:39

On Wed, Jan 11, 2017 at 2:10 PM, <stefanov.sm@abv.bg> wrote:
> The following bug has been logged on the website:
> This is a real life example - a simple function that makes text CP1251= -safe
> and 3 trivial queries. The first one is a test to determine whether th= e
> function incurs significant performance penalty (it does not). Executi= on
> time was 218 ms.
> Having specified explicit names to the select list expressions (these = names
> are the same as the names of the underlying columns) execution time so= ared
> to 9.1 sec.
> The third query is the same as the second one except that the given > expression names are not the same as the names of the underlying colum= ns.
> The execution time was back again to the comfortable 219 ms.

It seems to me your 1st and 3rd queries are the same, the 2nd is not,
as order by uses the expresion, not the field, "tovaritelnica". (
https://www.postgresql.org/docs/9.2/static/sql-se= lect.html#SQL-ORDERBY
: "Each expression can be the name or ordinal number of an output
column (SELECT list item), or it can be an arbitrary expression formed
from input-column values." )

1St:
> SELECT
... Output column
> data_in.clear_cp1251(tovaritelnica),
...
> ORDER BY tovaritelnica DESC
.. But ordered by field ( an expression ), as column is no named like it.
2Nd.
> SELECT
...
> data_in.clear_cp1251(tovaritelnica) AS tovaritelnica,
...
> ORDER BY tovaritelnica DESC
Now ordering by output column, it shadows the name.

3Rd:
> SELECT
...
> data_in.clear_cp1251(tovaritelnica) AS _tovaritelnica,
....
> ORDER BY tovaritelnica DESC

Again, ordering by expresion =3D> field, no column.

Try specifying the column name as "data_in.ioground.tovaritelnica" in
the order by, or something similar. But remember 1st and 3rd query
select one thing but order by a different one.


Francisco Olarte.
------=_Part_46004_1373305228.1484163151748--