Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 11DF71337B51 for ; Sun, 19 Dec 2010 00:51:21 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 43750-07 for ; Sun, 19 Dec 2010 04:51:13 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 4DF071337B43 for ; Sun, 19 Dec 2010 00:51:13 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id oBJ4p7mB016080; Sat, 18 Dec 2010 23:51:07 -0500 (EST) To: "" cc: pgsql-bugs@postgresql.org Subject: Re: BUG #5793: tsquery error In-reply-to: <201012180013.oBI0DPfc074511@wwwmaster.postgresql.org> References: <201012180013.oBI0DPfc074511@wwwmaster.postgresql.org> Comments: In-reply-to "" message dated "Sat, 18 Dec 2010 00:13:25 +0000" Date: Sat, 18 Dec 2010 23:51:06 -0500 Message-ID: <16079.1292734266@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201012/133 X-Sequence-Number: 28939 "" writes: > The expression 'a & !(c) | a & b' is interpreted as '( a | !c ) & a & b'. > select 'a & !(c) | a & b'::tsquery; > Subsequent "rewrites" of the same expression give inconsistent results: > select '(a & !(c | d)) | (a & b)'::tsquery; -> 'a & !(c | d) | a & b' > (correct) > select 'a & !(c | d) | a & b'::tsquery; -> '(a | !(c | d)) & a & b' (not > correct) Hmm. The immediate problem seems to be fixed by diff --git a/src/backend/utils/adt/tsquery.c b/src/backend/utils/adt/tsquery.c index db9236a474157a7851e2a80516e865c050543634..ba09b3b2ce7fcc0815edf4a4622663291d6f0b8f 100644 *** a/src/backend/utils/adt/tsquery.c --- b/src/backend/utils/adt/tsquery.c *************** makepol(TSQueryParserState state, *** 371,378 **** case PT_OPEN: makepol(state, pushval, opaque); ! if (lenstack && (opstack[lenstack - 1] == OP_AND || ! opstack[lenstack - 1] == OP_NOT)) { lenstack--; pushOperator(state, opstack[lenstack]); --- 371,378 ---- case PT_OPEN: makepol(state, pushval, opaque); ! while (lenstack && (opstack[lenstack - 1] == OP_AND || ! opstack[lenstack - 1] == OP_NOT)) { lenstack--; pushOperator(state, opstack[lenstack]); but I can't say that I've got much confidence in the rest of that function. It's an utter kluge. regards, tom lane