MySQL - RANDOMLY choose a row in a 14Millions rows table - testing does not make sense -


I'm looking at the web to select a random line on the big table, I have found many results, but Then I analyzed my data and found out that the best way for me is to count the rows and one of these is to select random one with LIMIT

I wonder why this works:

  SET @t = CEIL (RAND (*) * (Select number from the logo Ed))); Select from logo ID WHERE current_status_id = 29 and logo_type_id = 4 and activate = 'y' and id & gt; = @ T ORDER ID range1;  

and gives random results, but does it always give the same 4 or 5 results?

  Select from WHERE current_status_id = 29 and logo_type_id = 4 and activate = 'y' and id> gt; = CEIL (RAND (* * * Logo logo select MAX (ID)) ID limit 1;  

The table has many fields (about 100) and many more indexes. More than 14 million records and counting When I make a random selection, it is almost not that I have to choose it from the table, I have to always choose on the basis of different field values ​​(all indexes).

Is this a bug version of my MySQL server ( 5.6.13-log creation distribution )?

There is a possibility that in this statement:

RAND () WHERE in a WHERE section is re-evaluated every time it is executed.

is not always true really it is true when you do:

  where rand () & lt; 0.01  

To obtain a sample of approximately 1% of the rows. Perhaps the MySQL adapter says something like "Oh, I'll evaluate the subquery to get a price back. And, to be just more efficient, I defined that line before defining with rand () I will continue. "

If I have to guess, then that will be the case.

Another possibility is that the data is arranged so that the values ​​you are looking for include one line ID in them. Or, it may be that in the beginning many lines have small IDs, and then there is a huge gap.

Your method of getting a random line is not guaranteed to go back. When you're filtering the results, I do not know if this is necessary for you.

Edit:

Check to see if this version expects you:

  Connect the logo to SELECT ID (maximum max Select the logo from the ID) C WHERE current_status_id = 29 and logo_type_id = 4 and activate = 'y' and id> = rand () * ID by maximum limit 1; If so, the problem is that the maximum ID is being calculated and then it is an additional step to multiply as the execution of the query by  rand () . begins. 


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

lua - HowTo create a fuel bar -