Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hpyW1-0003pZ-Vd for pgsql-general@arkaria.postgresql.org; Tue, 23 Jul 2019 17:23:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hpyW0-00066b-Rs for pgsql-general@arkaria.postgresql.org; Tue, 23 Jul 2019 17:23:52 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hpyVz-00065v-5A for pgsql-general@lists.postgresql.org; Tue, 23 Jul 2019 17:23:52 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1hpyVr-0003fG-Lk for pgsql-general@postgresql.org; Tue, 23 Jul 2019 17:23:49 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 8207220D2D; Tue, 23 Jul 2019 13:23:42 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 23 Jul 2019 13:23:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=8 oD13lWjWcON0wG3c5M9WpQ8v7X240/XbIa9t1TyUkA=; b=lcXx1SRQkF+VMq6dc qsQYd24PNu2ACgIt/SZ4R+EsrdGl+vy8fySwIyNkCQ/nKjTfvQn/W7kD+V4n4DaZ lIoq/VuTm57yNMAC3IqlST66AuEb1svafBpRe5zZa96u1L9OI2PCkxmrI+ZxWCJB Fk82OQg/BFexQ4dKGfSTdlt3PaP8iPOamk0PWTZKalUDfuKm49kZWc6yB0ADMvSK lBfKIz+G7GAQ4/gPHrizH3wLchbXl4NiH3dLhrDlylTCEXaKxk6dpQ4tu/rAAj0L IqX97G6aaxm9Bu+PCNA2+6JXGp65k9hvjQxShaPeRoe9hwHUtsBnJ859i2GkUj0U KqgEg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=8oD13lWjWcON0wG3c5M9WpQ8v7X240/XbIa9t1TyU kA=; b=IE4VZGyfiQH9R3OBiaK8dnGweqIWlwfD7EkcGxC00oGCWuNA0USs3072Q UfNNjhl3iTc/AT1n5xsndRBwdqDSGvj6IZ528DFbqH6tPD5Mr5Qwx44GRB39LwLV j9IUvBL1xVx3nZciMe8/CBHPNsRRbAVj+lLB5THWFb+qc5O6p45AHQ42hGV0DEHz i3Qg4lMu0i7qPfDZuGIxtv72D9IfXgeGeLMVH15Cf8E6mwBRA9G5QOZ6Z9EGz/eA ED3KGv1cH/uoUzGV7hsEh+LuLMgHQvLchFMhdaO3nwjmHuPfPv+ib/cpuc3tQNFk mAZYQGRGNwdKOmcnXabjKCHOeZU9g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrjeekgdduuddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthejredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgnecukfhppeejgedrleeg rdejfedrvddvvdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvh gvrhesrghklhgrvhgvrhdrtghomhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from ranger.suse (unknown [74.94.73.222]) by mail.messagingengine.com (Postfix) with ESMTPA id 7FBFB8005C; Tue, 23 Jul 2019 13:23:41 -0400 (EDT) Subject: Re: Default ordering option To: Cyril Champier , pgsql-general@postgresql.org References: From: Adrian Klaver Message-ID: Date: Tue, 23 Jul 2019 10:23:40 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 7/23/19 8:43 AM, Cyril Champier wrote: > Hi, > > In this documentation > , it is said: > > If sorting is not chosen, the rows will be returned in an > unspecified order. The actual order in that case will depend on the > scan and join plan types and the order on disk, but it must not be > relied on. > > > I would like to know if there is any way to change that to have a "real" > random behaviour. > > My use case: > At Doctolib, we do a lot of automatic tests. > Sometimes, people forgot to order their queries. Most of the time, there > is no real problem on production. Let say, we display a user list > without order. > When a developer writes a test for this feature, he will create 2 users > A and B, then assert that they are displayed "[A, B]". > 99% of the time the test will be ok, but sometimes, the displayed list > will be "[B,A]", and the test will fail. > > One solution could be to ensure random order with an even distribution, > so that such failing test would be detected quicker. > > Is that possible? Maybe with a plugin? Not that I know of. A possible solution given below: test_(postgres)> insert into t1 values (1, 'dog'), (2, 'cat'), (3, 'fish'); INSERT 0 3 test_(postgres)> select * from t1 ; a | b ---+------ 1 | dog 2 | cat 3 | fish (3 rows) test_(postgres)> update t1 set b = 'dogfish' where a =1; UPDATE 1 test_(postgres)> select * from t1 ; a | b ---+--------- 2 | cat 3 | fish 1 | dogfish (3 rows) An UPDATE reorders the rows. Maybe throw an UPDATE into the test after creating the users to force an 'out of order' result? > > Thanks, > Cyril > > > -- Adrian Klaver adrian.klaver@aklaver.com