petr , IN, MyISAM InnoDB.
MyISAM
ALTER TABLE Transactions ADD INDEX cover_1 (PK, Stamp)
Or, for InnoDB, where PK is implicitly included in each index,
ALTER TABLE Transactions ADD INDEX Stamp (Stamp)
Then
SELECT *
FROM Transactions LEFT JOIN
(
SELECT PK
FROM Transactions
WHERE DAYOFMONTH(Stamp - interval 3 hour) = 1
) a ON Transactions.PK=a.PK
Only the index will be executed in the subquery, and the external query will pull rows only from the table in which a.PK was located.
source
share