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 1faIhQ-0003XB-FG for pgsql-general@arkaria.postgresql.org; Tue, 03 Jul 2018 10:38:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1faIhO-0000rS-0V for pgsql-general@arkaria.postgresql.org; Tue, 03 Jul 2018 10:38:18 +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 1faIhN-0000rL-Lj for pgsql-general@lists.postgresql.org; Tue, 03 Jul 2018 10:38:17 +0000 Received: from mx1.mailbox.org ([80.241.60.212]) by makus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1faIhK-0005YT-Eq for pgsql-general@postgresql.org; Tue, 03 Jul 2018 10:38:16 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.mailbox.org (Postfix) with ESMTPS id 4EDBB43793; Tue, 3 Jul 2018 12:38:10 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter01.heinlein-hosting.de (spamfilter01.heinlein-hosting.de [80.241.56.115]) (amavisd-new, port 10030) with ESMTP id IuoqWobM4IQq; Tue, 3 Jul 2018 12:38:08 +0200 (CEST) Message-ID: <1530614287.2486.40.camel@cybertec.at> Subject: Re: Analyze plan of foreign data wrapper From: Laurenz Albe To: Mathieu PUJOL , pgsql-general@postgresql.org Date: Tue, 03 Jul 2018 12:38:07 +0200 In-Reply-To: References: <1530220664.3220.2.camel@cybertec.at> Organization: Cybertec Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Mathieu PUJOL wrote: > I understand that I should also use varno to check which table is referenced by varattno. In case of Join, aggregation, etc. Sometimes I get a number or INNER_VAR or OUTER_VAR. > I am lost on how i could resolve this. > I understand that OUTER_VAR/INNER_VAR are related to joins sub plans. Is outer related to left plan and inner to right plan ? In this case varattno is index of target list of subplan ? > When varno is an index how to retrieve table info ? I have no deep understanding of these things. Maybe the following comment from include/nodes/primnodes.h can help: /* * Var - expression node representing a variable (ie, a table column) * * Note: during parsing/planning, varnoold/varoattno are always just copies * of varno/varattno. At the tail end of planning, Var nodes appearing in * upper-level plan nodes are reassigned to point to the outputs of their * subplans; for example, in a join node varno becomes INNER_VAR or OUTER_VAR * and varattno becomes the index of the proper element of that subplan's * target list. Similarly, INDEX_VAR is used to identify Vars that reference * an index column rather than a heap column. (In ForeignScan and CustomScan * plan nodes, INDEX_VAR is abused to signify references to columns of a * custom scan tuple type.) In all these cases, varnoold/varoattno hold the * original values. The code doesn't really need varnoold/varoattno, but they * are very useful for debugging and interpreting completed plans, so we keep * them around. */ #define INNER_VAR 65000 /* reference to inner subplan */ #define OUTER_VAR 65001 /* reference to outer subplan */ #define INDEX_VAR 65002 /* reference to index column */ #define IS_SPECIAL_VARNO(varno) ((varno) >= INNER_VAR) Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com