Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kc8oW-0002fL-JJ for pgsql-general@arkaria.postgresql.org; Mon, 09 Nov 2020 15:10:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kc8oV-0003Qa-5r for pgsql-general@arkaria.postgresql.org; Mon, 09 Nov 2020 15:10:35 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kc8oU-0003QS-UJ for pgsql-general@lists.postgresql.org; Mon, 09 Nov 2020 15:10:34 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kc8oS-0005co-RS for pgsql-general@postgresql.org; Mon, 09 Nov 2020 15:10:33 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 0A9FAUPq1974196; Mon, 9 Nov 2020 10:10:30 -0500 From: Tom Lane To: Davide Jensen cc: pgsql-general@postgresql.org Subject: Re: Different result behavior when using ANY(ARRAY(SELECT)) and IN (SELECT) In-reply-to: References: Comments: In-reply-to Davide Jensen message dated "Mon, 09 Nov 2020 12:30:34 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1974194.1604934630.1@sss.pgh.pa.us> Date: Mon, 09 Nov 2020 10:10:30 -0500 Message-ID: <1974195.1604934630@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Davide Jensen writes: > I'm encountering some problems in understanding the behavior of a query > that uses an IN operator, the query i'm executing is the following: > SELECT * FROM ( > SELECT _id, > ROW_NUMBER() OVER () AS _rownumber I think your problem is in the above, not anything later in the query. ROW_NUMBER without any ordering specification is indeterminate. If the query gets parallelized, it's no surprise that the selected rows will be processed in varying order from one try to the next. Your second phrasing of the query seems to be non-parallelizable, but the row_number() result is still pretty indeterminate; it just doesn't happen to have changed within your test run. What is it you are expecting to get out of including a fictional row number in the query result, anyway? regards, tom lane