Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1muRkl-0005ZD-8i for pgsql-general@arkaria.postgresql.org; Tue, 07 Dec 2021 04:06:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1muRkk-0007eA-0w for pgsql-general@arkaria.postgresql.org; Tue, 07 Dec 2021 04:06:54 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1muRkj-0007e1-LS for pgsql-general@lists.postgresql.org; Tue, 07 Dec 2021 04:06:53 +0000 Received: from mail-qk1-x729.google.com ([2607:f8b0:4864:20::729]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1muRkg-0001wX-KQ for pgsql-general@lists.postgresql.org; Tue, 07 Dec 2021 04:06:53 +0000 Received: by mail-qk1-x729.google.com with SMTP id w14so5019844qkf.5 for ; Mon, 06 Dec 2021 20:06:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to:content-transfer-encoding; bh=ks9pS52h6kxGS1nCPlKTzStzf5DH0vnGSvgu1JIepBM=; b=dqBQ4T3C5PZP17IMzfpJmibPg8PT+z/czmZRH8eMFwixp0rIyxwJZ1lDD3zpCnl/jL zaFc7SuxyqbppwtA0PRNrKVMG0Ik/1t3qxzk5OJFsd+UE3w4lOfs1Mem5cnUKZt7wk+t t87z0yR7g2SHsiCKYCc257YsIYYPs9YBc5Y6mdQCmNqiYXcMn/lAoa1OKipGGbkJT07z c9D5iDiXbk6NyX0L1jT7uDDutMSn7330dpZZ+RdjhqvrMD3SN5OrKcTXlU9clTK9VNVL nzVehogqBW2wr+evyPfHqizHrQtFrWokT9TYUwBpwAWoYBNm6hJc0/qfXHTrlMhTnO/t KgCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=ks9pS52h6kxGS1nCPlKTzStzf5DH0vnGSvgu1JIepBM=; b=WBLA4JXT2NfAnOtT2Bw1r0EMq/BU6D5Vur/DeETdzOUnnupE+kHVLMRI0ABf3sdBw0 8rqH4fBeNJWCG9hWY5GAn11Mgy2LJlVWup4HN6D+Vza87oPQwpn3KKj8gB4alykOFq09 MUSgOfJwB/CKJ7WMgoHp85qfHX6DOC6Hw9GNNwT5xn/qVzpZHODefMa27avvXVpRKr5h e2a2W6S6YgQuobdxiHRWxb/ggkNQN5ItNegYRoc8XaRXNNzpFBkT5Gh1IfQiUdH0T+ye F7yDEHMJt/mEuWUeR33TyfDDJeqxS2mGoWELni6cqhdAtLICAvqkDLzDQoPxFXCUYpWb ne4w== X-Gm-Message-State: AOAM5321p1EqcE028jNQ4XoLeVwSLARheP+NjaXaPey99zdC6Cyi2YNX SUD+dpTcKf5fn4OBwosy8bUtsbGNbr2p9Q== X-Google-Smtp-Source: ABdhPJwjsXKoM1RZyxkVjceay3KmIBsgzuCIubbOxddzS1YiBpIOqQFvkjwub7nNijdHZg5beWtkyw== X-Received: by 2002:a37:a5d3:: with SMTP id o202mr38264861qke.384.1638850008029; Mon, 06 Dec 2021 20:06:48 -0800 (PST) Received: from [192.168.2.100] (pool-72-79-19-93.nwrknj.east.verizon.net. [72.79.19.93]) by smtp.gmail.com with ESMTPSA id x16sm7463925qkp.67.2021.12.06.20.06.47 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 06 Dec 2021 20:06:47 -0800 (PST) Message-ID: Date: Mon, 6 Dec 2021 23:06:46 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.0 Subject: Re: Query planner issue with preferring primary key over a better index when using ORDER BY and LIMIT Content-Language: en-US To: pgsql-general@lists.postgresql.org References: <82b3a0d97f5ee6279f1c7e6048c510b07f0b313b.camel@cybertec.at> From: Mladen Gogala In-Reply-To: <82b3a0d97f5ee6279f1c7e6048c510b07f0b313b.camel@cybertec.at> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 12/6/21 22:16, Laurenz Albe wrote: > An ugly alternative is to use "ORDER BY id + 0", which prevents PostgreSQL > from using the index. That was actually the earliest form of Oracle hints. I remember doing exactly that in Oracle 5.1.22 on VAX/VMS. -- Mladen Gogala Database Consultant Tel: (347) 321-1217 https://dbwhisperer.wordpress.com