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.89) (envelope-from ) id 1gUbof-0000af-GU for pgsql-hackers@arkaria.postgresql.org; Wed, 05 Dec 2018 18:22:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gUboc-0006Vb-RU for pgsql-hackers@arkaria.postgresql.org; Wed, 05 Dec 2018 18:22:30 +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 1gUboc-0006VT-Gj for pgsql-hackers@lists.postgresql.org; Wed, 05 Dec 2018 18:22:30 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gUboZ-00038Y-Mi for pgsql-hackers@postgresql.org; Wed, 05 Dec 2018 18:22:29 +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 wB5IMNEN008211; Wed, 5 Dec 2018 13:22:23 -0500 From: Tom Lane To: Andres Freund cc: Pavel Stehule , PostgreSQL Hackers Subject: Re: slow queries over information schema.tables In-reply-to: <20181205175657.s7mt6as356kwvrji@alap3.anarazel.de> References: <5978.1544030694@sss.pgh.pa.us> <20181205175657.s7mt6as356kwvrji@alap3.anarazel.de> Comments: In-reply-to Andres Freund message dated "Wed, 05 Dec 2018 09:56:57 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <8209.1544034143.1@sss.pgh.pa.us> Date: Wed, 05 Dec 2018 13:22:23 -0500 Message-ID: <8210.1544034143@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Andres Freund writes: > On 2018-12-05 12:24:54 -0500, Tom Lane wrote: >> There are two different issues in that. One is that the domain might >> have constraints (though in reality it does not), so the planner can't >> throw away the CoerceToDomain node, and thus can't match the expression >> to the index. Even if we did throw away the CoerceToDomain, it still >> would not work because the domain is declared to be over varchar, and >> so there's a cast-to-varchar underneath the CoerceToDomain. > Couldn't we make expression simplification replace CoerceToDomain with a > RelabelType if the constraint is simple enough? That's not entirely > trivial because we'd have to look into the typecache to get the > constraints, but that doesn't sound too bad. Not following what you have in mind here? My 0002 throws away the CoerceToDomain if there are *no* constraints, but I can't see any situation in which we'd likely be able to ignore a constraint, simple or not. >> 0003 essentially converts "namecol::text texteq textvalue" into >> "namecol nameeqtext textvalue", relying on the new equality >> operator introduced by 0001. > Ugh, that's indeed a bit kludgy. It'd be nice to have an approach that's > usable outside of one odd builtin type. I was wondering for a bit > whether we could have logic to move the cast to the other side of an > operator, but I don't see how we could make that generally safe. Yeah. It seems like it could be a special case of a more general expression transform facility, but we have no such facility now. On the other hand, all of match_special_index_operator is an ugly single-purpose kluge already, so I'm not feeling that awful about throwing another special case into it. Someday it would be nice to replace that code with something more general and extensible, but today is not that day as far as I'm concerned. regards, tom lane