Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1awBTw-0008GT-80 for pgsql-hackers@arkaria.postgresql.org; Fri, 29 Apr 2016 16:41:32 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1awBTv-00054n-QV for pgsql-hackers@arkaria.postgresql.org; Fri, 29 Apr 2016 16:41:31 +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.84_2) (envelope-from ) id 1awBSR-0000tB-V1 for pgsql-hackers@postgresql.org; Fri, 29 Apr 2016 16:39:59 +0000 Received: from mimolette.dalibo.net ([212.85.157.144] helo=mail.dalibo.com) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1awBSO-0002Wg-8A for pgsql-hackers@postgresql.org; Fri, 29 Apr 2016 16:39:59 +0000 Received: from [192.168.0.6] (aur75-1-78-192-238-147.fbxo.proxad.net [78.192.238.147]) by mail.dalibo.com (Postfix) with ESMTPSA id CCD2C2C2918; Fri, 29 Apr 2016 18:39:54 +0200 (CEST) Subject: Re: pg9.6 segfault using simple query (related to use fk for join estimates) To: Tom Lane References: <20160429102531.GA13701@huehner.biz> <572384D7.1020602@dalibo.com> <17639.1461945908@sss.pgh.pa.us> Cc: Michael Paquier , Stefan Huehner , PostgreSQL mailing lists , Tomas Vondra From: Julien Rouhaud Message-ID: <57238E64.8010702@dalibo.com> Date: Fri, 29 Apr 2016 18:40:04 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 MIME-Version: 1.0 In-Reply-To: <17639.1461945908@sss.pgh.pa.us> Content-Type: multipart/mixed; boundary="------------020003070307060801060605" X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org This is a multi-part message in MIME format. --------------020003070307060801060605 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit On 29/04/2016 18:05, Tom Lane wrote: > Julien Rouhaud writes: >> The segfault is caused by quals_match_foreign_key() calling get_leftop() >> and get_rightop() on a ScalarArrayOpExpr node. > >> Reordering the common fields of OpExpr and ScalarArrayOpExpr at the >> beginning of the struct so the get_*op() work with either (as in >> attached patch) fixes the issue. > >> I'm not sure that assuming this compatibility is the right way to fix >> this though. > > It certainly isn't. > Agreed. New attached patch handles explicitly each node tag. -- Julien Rouhaud http://dalibo.com - http://dalibo.org --------------020003070307060801060605 Content-Type: text/plain; charset=UTF-8; name="fix_opexpr.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="fix_opexpr.diff" diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/u= til/clauses.c index 759566a..3b9715b 100644 --- a/src/backend/optimizer/util/clauses.c +++ b/src/backend/optimizer/util/clauses.c @@ -100,6 +100,7 @@ typedef struct bool allow_restricted; } has_parallel_hazard_arg; =20 +static List *get_opargs(const Expr *clause); static bool aggregates_allow_partial_walker(Node *node, partial_agg_context *context); static bool contain_agg_clause_walker(Node *node, void *context); @@ -197,6 +198,19 @@ make_opclause(Oid opno, Oid opresulttype, bool opretse= t, return (Expr *) expr; } =20 +static List * +get_opargs(const Expr *clause) +{ + if (IsA(clause, OpExpr)) + return ((OpExpr *) clause)->args; + + if (IsA(clause, ScalarArrayOpExpr)) + return ((ScalarArrayOpExpr *) clause)->args; + + elog(ERROR, "unrecognized node type: %d", + (int) nodeTag(clause)); +} + /* * get_leftop * @@ -206,10 +220,10 @@ make_opclause(Oid opno, Oid opresulttype, bool oprets= et, Node * get_leftop(const Expr *clause) { - const OpExpr *expr =3D (const OpExpr *) clause; + const List *args =3D get_opargs(clause); =20 - if (expr->args !=3D NIL) - return linitial(expr->args); + if (args !=3D NIL) + return linitial(args); else return NULL; } @@ -223,10 +237,10 @@ get_leftop(const Expr *clause) Node * get_rightop(const Expr *clause) { - const OpExpr *expr =3D (const OpExpr *) clause; + const List *args =3D get_opargs(clause); =20 - if (list_length(expr->args) >=3D 2) - return lsecond(expr->args); + if (list_length(args) >=3D 2) + return lsecond(args); else return NULL; } --------------020003070307060801060605 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers --------------020003070307060801060605--