Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ckvmU-00063a-8g for pgsql-performance@arkaria.postgresql.org; Mon, 06 Mar 2017 16:46:42 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1ckvmT-0005WB-JX for pgsql-performance@arkaria.postgresql.org; Mon, 06 Mar 2017 16:46:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ckvmT-0005W1-2N for pgsql-performance@postgresql.org; Mon, 06 Mar 2017 16:46:41 +0000 Received: from mwork.nabble.com ([162.253.133.43]) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ckvmM-0007iu-D6 for pgsql-performance@postgresql.org; Mon, 06 Mar 2017 16:46:40 +0000 Received: from mben.nabble.com (unknown [162.253.133.72]) by mwork.nabble.com (Postfix) with ESMTP id 64C3D3126B0AF for ; Mon, 6 Mar 2017 09:46:32 -0700 (MST) Date: Mon, 6 Mar 2017 09:46:32 -0700 (MST) From: twoflower To: pgsql-performance@postgresql.org Message-ID: <1488818792254-5947737.post@n3.nabble.com> In-Reply-To: References: <1488810146219-5947712.post@n3.nabble.com> Subject: Re: Huge difference between ASC and DESC ordering MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_10295_710692913.1488818792411" X-Pg-Spam-Score: -0.3 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org ------=_Part_10295_710692913.1488818792411 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Thank you Jeff. There are 7 million rows satisfying fk_id_client = 20045. There is an index on fk_id_client, now I added a composite (fk_id_client, id) index but that did not help. I see the point of what you are saying, but still don't understand how these two situations (*asc* vs. *desc*) are not symmetrical. I mean, there /is/ an ascending index on *JOB_MEMORY.id*, so why does it matter which end I am picking the data from? The thing is, even when I force Postgres to use the ascending index on *id*, it's still orders of magnitude slower than the *desc* version (even when that one goes through the index backwards). -- View this message in context: http://www.postgresql-archive.org/Huge-difference-between-ASC-and-DESC-ordering-tp5947712p5947737.html Sent from the PostgreSQL - performance mailing list archive at Nabble.com. ------=_Part_10295_710692913.1488818792411 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit Thank you Jeff.

There are 7 million rows satisfying fk_id_client = 20045. There is an index on fk_id_client, now I added a composite (fk_id_client, id) index but that did not help.

I see the point of what you are saying, but still don't understand how these two situations (asc vs. desc) are not symmetrical. I mean, there is an ascending index on JOB_MEMORY.id, so why does it matter which end I am picking the data from?

The thing is, even when I force Postgres to use the ascending index on id, it's still orders of magnitude slower than the desc version (even when that one goes through the index backwards).

View this message in context: Re: Huge difference between ASC and DESC ordering
Sent from the PostgreSQL - performance mailing list archive at Nabble.com.
------=_Part_10295_710692913.1488818792411--