Re: remove gaps in a table

From: Peter H. Coffin <hellsop_at_ninehells.com>
Date: Sun, 31 Dec 2017 22:20:46 -0600
Message-ID: <slrnp4jdou.d0s.hellsop_at_nibelheim.ninehells.com>


On Thu, 21 Dec 2017 00:13:16 +0100, mireero wrote:
> I get it, don't touch the order_number.
> Actually, I like the idea of filling gaps with void orders.
>
> I am still wondering how one could find the first gap, using mysql only ?
> I mean, the lowest order_number that is non existing.
> Or I could say, the highest order_number before any gap + 1.
>
> To be complete:
> I created the gaps by manually deleting fake/testing rows in the table.
> I don't have access to a dev/test server...
> AFAIK, I'm the only "source" of gaps, so it should be fine in the future.
>
> Thanks everyone, I appreciated your comments !

I'm ... Okay. Point of philosophy. Row ids are row ids. Their only meaning is to identify the row, and that's the only primary key. Other things can be indexed and become foreign keys in other tables. Row IDs never ever ever change, AND you don't worry about "gaps" or linearity, because those ids have no meaning. If you need to set an autoinc, while offline, you find max() for the id, add one, and set.

-- 
If sharing a thing in no way diminishes it, it is not rightly owned if 
it is not shared. -- St. Augustine
Received on Mon Jan 01 2018 - 05:20:46 CET

Original text of this message