Skip to content
Advertisement

SELECT COUNT with JOIN optimization for tables with > 100M rows

I have following query

— EDIT —

Most of you have focused on GROUP BY and SUBSTRING, but this is not the root of problem.

Following query have the same execution time:

— EDIT 2 —

After adding index on applications.created_date and forcing the query to use specified indexes as @DDS suggests the execution time drops to ~750ms

The current query looks like:

— EDIT 3 —

I have found that using to much indexes in query may cause that in some cases MySQL will use non optimal indexes, so the final query should looks as following:

— END EDIT —

package_codes contains over 100.000.000 records.

applications contains over 250.000 records.

The query takes 2 minutes to get result. Is there any way to optimize it? I’m stuck on MySQL 5.5.

Tables:

Advertisement

Answer

After adding index on applications.created_date and forcing the query to use specified indexes as @DDS suggests the execution time drops to ~750ms

The final query should look as following:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement