O
O
Oleg Otkidach2021-06-06 14:12:50
PHP
Oleg Otkidach, 2021-06-06 14:12:50

Why is it long with phpmyadmin and fast with php (SQL query with nested query-condition)?

I have such a problem.
When working through phpmyadmin, SQL queries of the form

SELECT *
FROM `table-1`
WHERE `table-2-id` IN
    (
        SELECT `id` 
        FROM `table-2`
        WHERE `condition` = 'condition-value'
    )

i.e., requests with a nested query condition
are executed brutally long, it is actually impossible to wait for them, even if the condition is very simple, the data volumes are quite small (thousands of records, even hundreds, maybe).

Moreover, if you write such requests in the php code, then everything flies normally.
But often I would like to view the data through phpmyadmin.

What is the reason for this, is it possible to solve this (relatively speaking, is there a certain checkmark in phpmyadmin that needs to be unchecked in order to help matters)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nokimaro, 2021-06-06
@nokimaro

Phpmyadmin for select queries tries to automatically add LIMIT but first executes the same query with SQL_CALC_FOUND_ROWS
Try repeating your query with an explicit LIMIT at the end

SELECT *
FROM `table-1`
WHERE `table-2-id` IN
    (
        SELECT `id` 
        FROM `table-2`
        WHERE `condition` = 'condition-value'
    ) LIMIT 999999

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question