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 1ftc7Y-0003Yp-F4 for pgsql-bugs@arkaria.postgresql.org; Sat, 25 Aug 2018 17:13:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ftc7W-0000rf-G1 for pgsql-bugs@arkaria.postgresql.org; Sat, 25 Aug 2018 17:13:06 +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.89) (envelope-from ) id 1ftc7W-0000rY-A8 for pgsql-bugs@lists.postgresql.org; Sat, 25 Aug 2018 17:13:06 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ftc7T-0001uJ-FF; Sat, 25 Aug 2018 17:13:05 +0000 Received: from [192.168.127.1] (port=22525 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 1ftc7P-0004Ef-PY; Sat, 25 Aug 2018 17:12:59 +0000 Received: from [127.0.0.1] (port=55096 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1ftc7O-000DEE-Nk; Sat, 25 Aug 2018 17:12:58 +0000 From: Andrew Gierth To: pgsql-bugs@lists.postgresql.org Cc: maxim.boguk@gmail.com, rhaas@postgresql.org, Ashutosh Bapat Subject: Re: BUG #15352: postgresql FDW error "ERROR: ORDER BY position 0 is not in select list" In-Reply-To: <87efemzw0v.fsf@news-spur.riddles.org.uk> (Andrew Gierth's message of "Sat, 25 Aug 2018 09:50:13 +0100") Message-ID: <87a7paz8b1.fsf@news-spur.riddles.org.uk> References: <153518420278.1478.14875560810251994661@wrigleys.postgresql.org> <87efemzw0v.fsf@news-spur.riddles.org.uk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Sat, 25 Aug 2018 18:12:58 +0100 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "Andrew" == Andrew Gierth writes: Andrew> So what's happening here is that there's an equivalence class Andrew> containing members Andrew> "greatest(pg_catalog.pg_stat_user_tables.idx_scan, Andrew> public.pg_stat_user_tables.idx_scan)" and "0" (as an integer Andrew> constant), and somehow a pathkey for this eclass is becoming Andrew> attached to the query going to the remote for statistics Andrew> purposes. Andrew> It seems obviously wrong that a constant pathkey with no actual Andrew> reference to the foreign table should be being pushed down, so Andrew> so far I suspect that get_useful_pathkeys_for_relation isn't Andrew> being selective enough about what is "useful". In this context Andrew> I find it suspicious that find_em_expr_for_rel will return an Andrew> expr with no vars as being "for" every rel, since it's just Andrew> looking for a subset. So this looks to me like an oversight in aa09cd242 (CCing rhaas and Ashutosh accordingly), which changed find_em_expr_for_rel from using bms_equal to bms_is_subset without considering the degenerate case of members with no relids at all. I propose to simply add a !bms_is_empty condition there; anyone have any better idea? -- Andrew (irc:RhodiumToad)