Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optimise MySQL reading pattern

I have an Integer-collection with filtered row-IDs in which I am trying to search for sequences/ranges to optimise a MySQL select-query. To give you an example:

The Integer-Collection can be either very fragmented:

[1,2,88,101,200] = Sequence(1-2,88,101,200)

Or very entirely:

[1,2,3,4,..,198,199,200] = Sequence(1-200)

Is there any Java-algorithm to find a sequence in the collection or to improve my reading-pattern in general?

like image 440
Michael Stauffer Avatar asked Aug 05 '26 04:08

Michael Stauffer


1 Answers

How long are your collections? Unless you have millions of items, it is probably fastest to load a collection entirely into memory, sort it and then scan for ranges.

In a sorted list, finding ranges is trivial. Just scan it sequentially; if the next element is not previous element + 1, one range has just ended, and another began.

like image 80
9000 Avatar answered Aug 07 '26 19:08

9000



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!