pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Julien Rouhaud <julien.rouhaud@dalibo.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Michael Paquier <michael.paquier@gmail.com>
Cc: Stefan Huehner <stefan@huehner.org>
Cc: PostgreSQL mailing lists <pgsql-hackers@postgresql.org>
Cc: Tomas Vondra <tomas.vondra@2ndquadrant.com>
Subject: Re: pg9.6 segfault using simple query (related to use fk for join estimates)
Date: Fri, 29 Apr 2016 18:40:04 +0200
Message-ID: <57238E64.8010702@dalibo.com> (raw)
In-Reply-To: <17639.1461945908@sss.pgh.pa.us>
References: <20160429102531.GA13701@huehner.biz>
	<CAB7nPqRj2EsGdoNESsWVC-RHV918Scd1xQEcYt3dK9Rs5RpuAQ@mail.gmail.com>
	<572384D7.1020602@dalibo.com>
	<17639.1461945908@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

On 29/04/2016 18:05, Tom Lane wrote:
> Julien Rouhaud <julien.rouhaud@dalibo.com> 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

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Attachments:

fix_opexpr.diff (text/plain, 1.6K) download diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/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; +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 opretset, return (Expr *) expr; } +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 opretset, Node * get_leftop(const Expr *clause) { - const OpExpr *expr = (const OpExpr *) clause; + const List *args = get_opargs(clause); - if (expr->args != NIL) - return linitial(expr->args); + if (args != 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 = (const OpExpr *) clause; + const List *args = get_opargs(clause); - if (list_length(expr->args) >= 2) - return lsecond(expr->args); + if (list_length(args) >= 2) + return lsecond(args); else return NULL; }

view thread (50+ messages)  latest in thread

Message-ID: <57238E64.8010702@dalibo.com>
Permalink:  ../57238E64.8010702@dalibo.com/
Also on:    postgresql.org/message-id/57238E64.8010702@dalibo.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: julien.rouhaud@dalibo.com, tgl@sss.pgh.pa.us, michael.paquier@gmail.com, stefan@huehner.org, tomas.vondra@2ndquadrant.com
  Subject: Re: pg9.6 segfault using simple query (related to use fk for join estimates)
  In-Reply-To: <57238E64.8010702@dalibo.com>
  References: <20160429102531.GA13701@huehner.biz> <CAB7nPqRj2EsGdoNESsWVC-RHV918Scd1xQEcYt3dK9Rs5RpuAQ@mail.gmail.com> <572384D7.1020602@dalibo.com> <17639.1461945908@sss.pgh.pa.us> <57238E64.8010702@dalibo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox