Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jDrY1-0000gQ-Lb for pgsql-bugs@arkaria.postgresql.org; Mon, 16 Mar 2020 15:20:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jDrXz-0001be-8M for pgsql-bugs@arkaria.postgresql.org; Mon, 16 Mar 2020 15:20:55 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jDrXy-0001bF-Ss for pgsql-bugs@lists.postgresql.org; Mon, 16 Mar 2020 15:20:55 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jDrXw-0001E6-Db for pgsql-bugs@lists.postgresql.org; Mon, 16 Mar 2020 15:20:53 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id 02GFKha4005149; Mon, 16 Mar 2020 11:20:43 -0400 From: Tom Lane To: Horimoto Yasuhiro cc: david.g.johnston@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16303: A condtion whether an index-only scan is possible includes a wrong In-reply-to: <20200316.172230.2295109568745072390.horimoto@clear-code.com> References: <16303-889581eb40fc0691@postgresql.org> <20200316.150533.1702058889215288265.horimoto@clear-code.com> <20200316.172230.2295109568745072390.horimoto@clear-code.com> Comments: In-reply-to Horimoto Yasuhiro message dated "Mon, 16 Mar 2020 17:22:30 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <5147.1584372043.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 16 Mar 2020 11:20:43 -0400 Message-ID: <5148.1584372043@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Horimoto Yasuhiro writes: > So I think that choosing index-only scan for this case (false is returne= d by gistcanreturn() case) > isn't expected behavior. You're mistaken. An index-only scan is not only useful but potentially quite desirable for queries such as count(*); in the best case it ends up just counting the index entries without ever visiting the heap at all. It does look a bit weird that we might select an IOS for an index type that can't ever return any column values, but so far as I can see it should work fine. The index isn't being asked to do anything that it doesn't have to do anyway, ie, return the correct set of heap TIDs. Testing locally with a GIST index gives the right answers, too. > We found the problem I reported with PGroonga: > https://github.com/pgroonga/pgroonga/issues/101 > This problem causes an error because PGroonga can't return > IndexScanDesc::xs_itup but IndexScanDesc::xs_want_itup is true. > Because PostgreSQL requests index-only scan even when PGroonga > returns false by amcanreturn(). You should be returning an empty, zero-column tuple (either itup or htup format) in that situation. The limit of "I don't have any columns I can return" is to form a tuple with no columns, not to fail to form a tuple. regards, tom lane