I am trying to find sources that ONLY exist before a certain timestamp. This query seems very poor for work. Any idea of ββan optimization or index that can improve?
select distinct sourcesite from contentmeta where timestamp <= '2011-03-15' and sourcesite not in ( select distinct sourcesite from contentmeta where timestamp>'2011-03-15' );
There is a pointer to sourceite and timestamp, but the request still takes a lot of time
mysql> EXPLAIN select distinct sourcesite from contentmeta where timestamp <= '2011-03-15' and sourcesite not in (select distinct sourcesite from contentmeta where timestamp>'2011-03-15'); +----+--------------------+-------------+----------------+---------------+----------+---------+------+--------+-------------------------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+--------------------+-------------+----------------+---------------+----------+---------+------+--------+-------------------------------------------------+ | 1 | PRIMARY | contentmeta | index | NULL | sitetime | 14 | NULL | 725697 | Using where; Using index | | 2 | DEPENDENT SUBQUERY | contentmeta | index_subquery | sitetime | sitetime | 5 | func | 48 | Using index; Using where; Full scan on NULL key | +----+--------------------+-------------+----------------+---------------+----------+---------+------+--------+-------------------------------------------------+
source share