Re: Counting down
Date: Tue, 22 Aug 2017 19:39:38 -0400
Message-ID: <onif36$bpr$1_at_jstuckle.eternal-september.org>
On 8/22/2017 7:13 PM, Axel Schwenke wrote:
> On 22.08.2017 23:45, Jerry Stuckle wrote:
>> The order of rows in a table is unspecified unless you use the ORDER BY
>> clause. And you CAN specify a key like you indicated - but only if the
>> keys are contiguous - not something that is a good idea, because
>> deleting a single row can cause the wrong row to be returned.
>
> So what? The TO very explicitly postulated a situation where there is a
> number if rows with a contiguous primary key. Based on that assumption [1]
> the very first answer is correct. Period.
>
So - you prefer to answer the question instead of solving the problem.
>> And ORDER BY ... DESC isn't as slow as you think. Since there is an
>> index on the ORDER BY column (the primary key), MySQL can go X number of
>> records back in the index - which would be even faster than searching
>> for a specific key, even if it is a binary search.
>
> Not all table engines in MySQL support backward scanning on an index. On top
> of that, scanning for the n-th. entry is *not* a binary search and in
> general has the very probably worse efficiency O(n) vs. O(log N) for a
> binary search.
>
And exactly which ones do not support backward scanning? I suspect MyISAM doesn't, for instance.
I didn't say scanning the n-th entry is a binary search. I said searching for a specific key is a binary search. Learn to read.
>
> [1] I am sure you remember the TO. He was not recognized for asking
> specifically ... err ... sensible questions. In fact most of his questions
> originated from the rather stupid end of the spectrum. So now now he gets a
> stupid answer to a stupid [2] question. So what?
>
Sure, I remember him. And he may not always express himself clearly and not always know the right question to ask. But that does not mean you should give him a stupid answer.
> [2] Oh, yes! Stupid questions *do* exist
>
Yup, like most of the ones you ask.
-- ================== Remove the "x" from my email address Jerry Stuckle jstucklex_at_attglobal.net ==================Received on Wed Aug 23 2017 - 01:39:38 CEST