Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T4MgQ-0003aT-6L for pgsql-bugs@postgresql.org; Thu, 23 Aug 2012 01:58:06 +0000 Received: from mail-pb0-f46.google.com ([209.85.160.46]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T4MgO-0003Fi-LA for pgsql-bugs@postgresql.org; Thu, 23 Aug 2012 01:58:05 +0000 Received: by pbbrr13 with SMTP id rr13so412724pbb.19 for ; Wed, 22 Aug 2012 18:58:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=RMzQkmbwgPzucnESOOK7OfE+6dSqIA7/st0/hDTCcpI=; b=oiFh32IhYDVD2N//nNlAUNjLlq0K4p/zFSEiKaB/kFe+G80NXFx5xbc7w/xMigoRGB iujr/sLTlDaJPLQ9kG3n6dz78AWKxREN1bHdKt7mVtp4GS95G62L7dTgpEveoPh/h8SS W5/zYUdBSMsP1kEsE2pExQAGOPnw5yr/iePCh9sMP0oqiAfcPPZnWgs82BvIEq9z/UhQ m0y4qXVNdusvzA2vz8RDvN92wJfMf2piuxIOXBh3aNd9XnuUGmhsBNXOxoHs6TDzIy5b LR/K8Gcjz0P8UyC2IpS9ofrxj4y1EnTGuCiFG2GrqnvuYaGz3hM07mGL9Q6sQT6NsiuG 1Tgw== Received: by 10.68.213.5 with SMTP id no5mr689696pbc.24.1345687082958; Wed, 22 Aug 2012 18:58:02 -0700 (PDT) Received: from ayaki.localdomain (office1.postnewspapers.com.au. [150.101.171.128]) by mx.google.com with ESMTPS id pg9sm4878796pbb.26.2012.08.22.18.58.00 (version=SSLv3 cipher=OTHER); Wed, 22 Aug 2012 18:58:01 -0700 (PDT) Message-ID: <50358E25.9040105@ringerc.id.au> Date: Thu, 23 Aug 2012 09:57:57 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120717 Thunderbird/14.0 MIME-Version: 1.0 To: Denis Kolesnik CC: pgsql-bugs@postgresql.org Subject: Re: additional message to the bug #7499 References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQnFgLocRTSihUXwHRFCNYZjsakZcbKZl8M7jTKyz2x7uWG7Kr1jjEkc7mRPgeLAOP77jE0f X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201208/172 X-Sequence-Number: 33896 On 08/22/2012 08:36 AM, Denis Kolesnik wrote: > I have now VERY strong argument to consider it is as a bug: > > if there a understandable for SQL language sequence which sorts > in other fashion when adding "LIMIT". Underspecified sorts can have unstable results, that's allowed by the spec and is a reasonable performance optimisation. If you want stable sorts you have to provide a fully defined ordering. To say this is a bug is a bit like saying that undefined behaviour in C is a bug. It isn't, the language and compiler are giving you what they're supposed to, just not what you want. http://en.wikipedia.org/wiki/Undefined_behavior Unstable sorts are a common optimisation http://en.wikipedia.org/wiki/Sorting_algorithm#Stability and a very useful one. Not allowing Pg to use unstable sorts, or use different sorts for different query plans, would slow correct queries down to make an incorrect query like yours run how you expect. -- Craig Ringer