Please take a look at the following query:
SELECT cc.number_card
FROM customers_cards cc
JOIN customers_card_psp ccp
ON cc.id = ccp.card_id AND ccp.psp_id = '12' AND ccp.status = 'old_ofogh_koorosh'
JOIN xxx
ON xxx.card_number = cc.number_card
Note, xxx
is a temp table:
CREATE TEMPORARY TABLE xxx ( card_number varchar(191) COLLATE utf8mb4_unicode_ci )
Here is the result of EXPLAIN
when there is no index for xxx
table:
And here is the result of EXPLAIN
when there is a index xxx(card_number)
:
As you can see, in the no-index situation, less rows
get scanned. So, what’s preferred? Using an index or not?