Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dnWpc-0000hx-1M for pgsql-general@arkaria.postgresql.org; Thu, 31 Aug 2017 21:16:56 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dnWpa-0007Gb-FV for pgsql-general@arkaria.postgresql.org; Thu, 31 Aug 2017 21:16:54 +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.84_2) (envelope-from ) id 1dnWnA-0002u2-5E for pgsql-general@postgresql.org; Thu, 31 Aug 2017 21:14:24 +0000 Received: from smtpoutz26.laposte.net ([194.117.213.101] helo=smtp.laposte.net) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dnWn6-0000tj-Bu for pgsql-general@postgresql.org; Thu, 31 Aug 2017 21:14:22 +0000 Received: from smtp.laposte.net (localhost [127.0.0.1]) by lpn-prd-vrout014 (Postfix) with ESMTP id 99704121798 for ; Thu, 31 Aug 2017 23:14:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=laposte.net; s=mail0; t=1504214057; bh=ODXsbnpW9S6a2IfnGaZzelFr8Jr9C8tfbaDz6+GUd0w=; h=To:From:Subject:Date; b=LO+oB2sLCMIn+YQ4RdgiijkIeFqwSQgkbG1TFHnyakyvOiZV8kIjHtZ787JAL/9f0 jRukiDiYMnmQq6S7jbTRQ85YIktRuOSA/eOaIxgxFTq6FDg1FEe8zLRybcP7wGsNzr QOngFTDgoKIJFHseKavCIKUbl0bsDlvR/bCKipct04wuR9ORmRGosQAvY/Mn1Y7ZHF wzMe3cXS7wd5AdFADahxQAi7pSH+XsaXSRF0nuOCPA7FcqqsoQN+IdNUTYwkg29+R9 BCr7+Lk+kncPMOGS3RR6q62G1xWM4BoT/15366/xk9XPUJTtYXqJKRRGub7hIfkf7+ vKXXFHjtsVOtw== Received: from smtp.laposte.net (localhost [127.0.0.1]) by lpn-prd-vrout014 (Postfix) with ESMTP id 8BB2C12184C for ; Thu, 31 Aug 2017 23:14:17 +0200 (CEST) Received: from lpn-prd-vrin001 (lpn-prd-vrin001.prosodie [10.128.63.2]) by lpn-prd-vrout014 (Postfix) with ESMTP id 861A0121798 for ; Thu, 31 Aug 2017 23:14:17 +0200 (CEST) Received: from lpn-prd-vrin001 (localhost [127.0.0.1]) by lpn-prd-vrin001 (Postfix) with ESMTP id 7813036AEF8 for ; Thu, 31 Aug 2017 23:14:17 +0200 (CEST) Received: from [192.168.0.10] (bob75-4-82-229-193-17.fbx.proxad.net [82.229.193.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lpn-prd-vrin001 (Postfix) with ESMTPSA id 3C5C036AE90; Thu, 31 Aug 2017 23:14:17 +0200 (CEST) To: pgsql-general@postgresql.org From: "benj.dev" Subject: Problem with Lateral ? Message-ID: <3a161163-8dcc-19ee-3fc2-24306e6ea833@laposte.net> Date: Thu, 31 Aug 2017 23:15:08 +0200 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit X-VR-SrcIP: 82.229.193.17 X-VR-FullState: 0 X-VR-Score: 0 X-VR-Cause-1: gggruggvucftvghtrhhoucdtuddrfeelledrudekgdduheduucetufdoteggodetrfdotffvucfrrhho X-VR-Cause-2: fhhilhgvmecunfetrffquffvgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefvhffukfff X-VR-Cause-3: fgggtgfgsehtjeertddtfeejnecuhfhrohhmpedfsggvnhhjrdguvghvfdcuoegsvghnjhdruggvvhes X-VR-Cause-4: lhgrphhoshhtvgdrnhgvtheqnecukfhppeekvddrvddvledrudelfedrudejnecurfgrrhgrmhepmhho X-VR-Cause-5: uggvpehsmhhtphhouhhtpdhhvghloheplgduledvrdduieekrddtrddutdgnpdhinhgvthepkedvrddv X-VR-Cause-6: vdelrdduleefrddujedpmhgrihhlfhhrohhmpegsvghnjhdruggvvheslhgrphhoshhtvgdrnhgvthdp X-VR-Cause-7: rhgtphhtthhopehpghhsqhhlqdhgvghnvghrrghlsehpohhsthhgrhgvshhqlhdrohhrgh X-VR-AvState: No X-VR-State: 0 X-VR-State: 0 List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org I Have a request that produce a bad result. I'm able to rewrite this request in a form that always produce a good result. But I don't understand the real reason of the problem. I have tried to simplify the dataset but the problem doesn't appear with less data. The request produce 16 rows (but only 15 are expected) If I add a filter for the first column like : col1 = 'aaa' I get the 15 expected rows. But if I put the filter with col1 <> 'aaa' I get 0 rows and it's the same with col1 IS NULL col1 is not NULL give 16 rows. Some other strange elements - If I try to isolate the rows used in the different tables for this request in "test" tables and use the test tables the problem doesn't appear. - If I don't use the regexp_split_to_table function (but a simple equality), the problem doesn't appear (but in fact with the problematic dataset, no element contain the split separator). - If I remove the "sub.evnt IS NULL OR" part from the (sub.evnt IS NULL OR p.evnt IN (SELECT regexp_split_to_table(sub.evnt,'#'))) the problem doesn't appear. - The "cnt" can be different even if the input data are the same. - If I remove the "ORDER BY x.id" I can obtain more rows. So the idea is not to find a good way to write the request but just understand why these problem of "virtual" rows appears. Is the problem related to the imbrication of the LATERAL clause and regexp_split_to_table or not ? So the request was : The version of Postgres is "PostgreSQL 9.3.6 on x86 64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.8.2-19Ubuntu1) 4.8.2, 64-bit" === SELECT DISTINCT col1, date_start, date_end, evt, x.* FROM ( SELECT f.*, c.evt FROM tmp.debug1 f LEFT JOIN tmp.debug2 c ON f.sport=c.sport AND f.compet=c.code ) sub LEFT JOIN LATERAL (SELECT x.id, x.nom, (SELECT count(*) FROM mother_table_with_some_herited_childs p WHERE p.id = x.id AND date_evt::date BETWEEN sub.date_start AND sub.date_end AND (sub.evt IS NULL OR p.evt IN (SELECT regexp_split_to_table(sub.evt,'#'))) ) as cnt FROM tmp.debug3 c LEFT JOIN LATERAL (SELECT * FROM identify i WHERE i.id = c.id) x ON TRUE WHERE c.hash = sub.hash ORDER BY x.id ) x ON true --WHERE col1 = 'aaa' -- <> 'aaa' -- IS NULL -- IS NOT NULL === Thanks for your ideas -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general