Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T4NI8-0001DC-Gp for pgsql-bugs@postgresql.org; Thu, 23 Aug 2012 02:37:04 +0000 Received: from mail-pz0-f46.google.com ([209.85.210.46]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T4NI6-0006MP-RF for pgsql-bugs@postgresql.org; Thu, 23 Aug 2012 02:37:03 +0000 Received: by dady13 with SMTP id y13so156769dad.19 for ; Wed, 22 Aug 2012 19:37:01 -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=DkbyG1SlZZpvtKYtJUvD1DCqcQ50I85VvvPSly1LaxQ=; b=jhVYi12L2qCtauu/CcGEHAJvfy3NJWrERXduWVyCXfwk34/y4yMMQFT1+mYWAtkohk vE4uwkQ6cN8fab7IAKGu52yXBt8RbpNGnujfwOAnzdkOOzN4lCsk5uPthcdRZruqc9sM 5g9CbkkvOg0E8Dr+rT15hv0IxllrJPmY4XHrZWOKr5iUJ0jHDM76zMuoPpKcIxPAm3Cu DqjfWiWLdUk0xRbdGBGM8dK8kesQxc+ghZDY6q/0iKd5dbNR4WtTO6LFGvDtEEQ3bnXM zIhVHs+fQNuX/hImpFmQm8bWw8Bz9SNMkfYRaUKJeqHNOnnAdDbKT2NdXw7TWhVSc1yB 1CwQ== Received: by 10.68.237.38 with SMTP id uz6mr905563pbc.23.1345689421537; Wed, 22 Aug 2012 19:37:01 -0700 (PDT) Received: from ayaki.localdomain (office1.postnewspapers.com.au. [150.101.171.128]) by mx.google.com with ESMTPS id wh7sm4939124pbc.33.2012.08.22.19.36.58 (version=SSLv3 cipher=OTHER); Wed, 22 Aug 2012 19:37:00 -0700 (PDT) Message-ID: <50359748.7030005@ringerc.id.au> Date: Thu, 23 Aug 2012 10:36:56 +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, Kevin Grittner Subject: Re: bug #7499 additional comments References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQnNVqv7UmNlI6HREdORLLX62I46O+BBa+UqJZ0/kXlO6Mxhhg2tcIaCNcrdzsUFlTTxzfL9 X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201208/171 X-Sequence-Number: 33895 On 08/23/2012 04:12 AM, Denis Kolesnik wrote: > Suppose a person who has basic SQL knowledges would learn on praxis > how would result a query if a person adds the clause "limit 1" to it Then they just got bitten by not learning enough and not testing their code well enough; they were probably programming by recipe and copy-and-paste, not by learning the platform they're working with. http://www.postgresql.org/docs/9.1/static/sql-select.html#SQL-ORDERBY "The ORDER BY clause causes the result rows to be sorted according to the specified expression(s). If two rows are equal according to the leftmost expression, they are compared according to the next expression and so on. If they are equal according to all specified expressions, they are returned in an implementation-dependent order." It'd be really nice if every programming language and tool could be completely safe and easy, with no undefined, implementation-defined or inconsistent behaviour. Unfortunately, in the real world that doesn't happen because perfectly specified platforms are (a) really hard to actually write and (b) usually hard to optimise and thus slow. Suppose a person with basic C knowledge wrote this (utterly wrong and dangerous, do not use for anything) program: #include #include #include int main() { char * blah = (char*)malloc(10); strcpy(blah,"1234567890"); printf("%s\n", blah); } This program has *at* *least* one bug that'll cause it to run most of the time, but fail unpredictably, especially when used as part of a larger program rather than standalone. Failure will depend on platform, C library, kernel, compiler settings, and the contents of uninitialized memory. Is the platform responsible for the user shooting themselves in the foot because they didn't learn about null termination of strings, buffer over-runs, the dangers of using strcpy(), etc? To me it's a bug in the user's code, not the platform. Sure, the platform could be easier to use. It could add lots of bounds checks, prohibit raw memory access, use garbage collection instead of explicit pointer-based memory management, etc. Then you'd have a new platform called Java, which is very useful - but not really something you can use to write tiny programs that take microseconds to run, or high-performance operating system kernels. Even Java has plenty of traps and confusing characteristics. Anything to do with threads. finalize() methods. try {} catch {} finally {} constructs. Double-checked locking. Plenty more. That's in a language that was designed to be an easier and safer alternative to C. Everything is a compromise, including the SQL language and implementations of it. If Pg made underspecified sorts an error then lots of other people would scream "bug!" because pretty much every other database system lets you do this so it'd be a portability problem - and because it's a really useful behaviour for some purposes. If Pg's query planner always ensured that sorts were stable and always did the same sorts, people wouldn't use Pg because it'd be too slow. More importantly, PostgreSQL has no way of *knowing* for sure that the sort is underspecified. It can't know that the column you've specified isn't unique, or at least unique within the subset of data you're working with. It trusts you to know what you want. The trick is to read the documentation, learn, and test your code well. That's true of every language, even those that try to protect the programmer from their mistakes as much as possible. -- Craig Ringer