MySQL SELECT fist X rows without an index

Sandor :

I am looking for a way to execute a SELECT query on a large table without having to add any new indexes.

SELECT id FROM table_name WHERE column_1 = "" limit 100

there is bout 800,000 of these empty rows and about 5 million of filled ones.

In my mind there has to be a way where the database engine just starts reading the table from one end, collects the first 100 rows (regardless of the order) and stops. However with the above query it checks all the 5M rows.

I did search the internet with no answer. Could someone help me out. Thanks.

André Pletschette :

One way or the other, I would add an index to "column_1".

I am pretty sure MySQL does not give you any possibility to influences this.

What you can try is doing a Stored procedure, which does a select "SELECT id FROM table_name" then filters on "column_1 = """ and stops after counting 100 positives.

If there are any better methods, I'll be happy to hear.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=395167&siteId=1