Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fqcpA-0007jx-38 for pgsql-bugs@arkaria.postgresql.org; Fri, 17 Aug 2018 11:21:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fqcp7-0007Sz-9A for pgsql-bugs@arkaria.postgresql.org; Fri, 17 Aug 2018 11:21:45 +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.89) (envelope-from ) id 1fqcp6-0007Ss-WF for pgsql-bugs@lists.postgresql.org; Fri, 17 Aug 2018 11:21:45 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fqcoz-0003Ms-V0 for pgsql-bugs@lists.postgresql.org; Fri, 17 Aug 2018 11:21:43 +0000 Received: from [192.168.127.1] (port=64592 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1fqcot-000DDn-M9; Fri, 17 Aug 2018 11:21:31 +0000 Received: from [127.0.0.1] (port=22511 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1fqcot-0006uv-1R; Fri, 17 Aug 2018 11:21:31 +0000 From: Andrew Gierth To: Damir =?utf-8?Q?Ciganovi=C4=87-Jankovi=C4=87?= Cc: Langote_Amit_f8@lab.ntt.co.jp, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15334: Partition elimination not working as expected when using enum as partition key In-Reply-To: ("Damir \=\?utf-8\?Q\?Ciganovi\=C4\=87-Jankovi\=C4\=87\=22's\?\= message of "Fri, 17 Aug 2018 12:10:41 +0200") Message-ID: <87r2ix2qm1.fsf@news-spur.riddles.org.uk> References: <153442831773.1504.1930023229211807055@wrigleys.postgresql.org> <1fff2a8b-92ef-c9e0-6a57-0e887d95c62b@lab.ntt.co.jp> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Fri, 17 Aug 2018 12:21:30 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "Damir" =3D=3D Damir Ciganovi=C4=87-Jankovi=C4=87 writes: >> It's the Postgres EXPLAIN's code for expression deparsing that puts >> the '::cstring' there. I have to wonder why it couldn't just skip >> adding that and print it as simply 'A'::ab. However, I'm not sure if >> answer to that question is related to why partition pruning doesn't >> occur. I think what's happening there is this: the parameter value needs a cast from text to "ab"; this cast is an IO cast, so it becomes enum_in(textout('A'),oid), and simplify_function can process textout('A') as a constant (since textout is immutable) but not enum_in('A',oid) (because enum_in is only stable, since it depends on the enum label definitions). So the simplified expression becomes ('A'::cstring)::ab even though that's not actually a valid cast in normal circumstances. I haven't checked the partition code, but my guess is that since that's not a constant (due to the stable cast), it can't be used for pruning in pg10 (in pg11 it seems to get pruned at execution time).