Note that there are some explanatory texts on larger screens.

plurals
  1. POmore records takes less time
    primarykey
    data
    text
    <p>This is almost driving me insane</p> <p>I do the following query: </p> <pre><code>SELECT * FROM `photo_person` WHERE photo_person.photo_id IN (SELECT photo_id FROM photo_person WHERE `photo_person`.`person_id` ='1') </code></pre> <p>When I change the id, I get different processing time. Although it's all the same queries and tables. By changing the person_id I get the following:</p> <p>-- person_id=1 ( 3 total, Query took 0.4523 sec)</p> <p>-- person_id=2 ( 99 total, Query took 0.1340 sec)</p> <p>-- person_id=3 ( 470 total, Query took 0.0194 sec)</p> <p>-- person_id=4 ( 1,869 total, Query took 0.0024 sec)</p> <p>I do not understand how with the increase of the number of records/results the query time is lower. The table structures are very straight forward</p> <p>UPDATE: I have already disabled mysql query cache, so every time I run the query, I would get the same exact value (of course it varies on the milisecond level but this is can be neglected)</p> <p>UPDATE: table is MyISAM</p> <pre><code>CREATE TABLE IF NOT EXISTS `photo_person` ( `entry_id` int(11) NOT NULL AUTO_INCREMENT, `photo_id` int(11) NOT NULL DEFAULT '0', `person_id` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`entry_id`), UNIQUE KEY `PhotoID` (`photo_id`,`person_id`), KEY `photo_id` (`photo_id`), KEY `person_id` (`person_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=182072 ; </code></pre> <p>Here is the results of the profiling</p> <pre><code>+----------+------------+-----------------------------+ | Query_ID | Duration |Query | +----------+------------+-----------------------------+ | 1 | 0.45541200 | SELECT ...`person_id` ='1') | | 2 | 0.44833700 | SELECT ...`person_id` ='2') | | 3 | 0.45587800 | SELECT ...`person_id` ='3') | | 4 | 0.45074900 | SELECT ...`person_id` ='4') | +----------+------------+-----------------------------+ </code></pre> <p>now since the number are the same, it must be the caching :( So the aparently the caching kicks in a certain number of records or bytes</p> <pre><code>mysql&gt; SHOW VARIABLES LIKE "%cac%"; +------------------------------+------------+ | Variable_name | Value | +------------------------------+------------+ | binlog_cache_size | 32768 | | have_query_cache | YES | | key_cache_age_threshold | 300 | | key_cache_block_size | 1024 | | key_cache_division_limit | 100 | | max_binlog_cache_size | 4294963200 | | query_cache_limit | 1024 | | query_cache_min_res_unit | 4096 | | query_cache_size | 1024 | | query_cache_type | ON | | query_cache_wlock_invalidate | OFF | | table_definition_cache | 256 | | table_open_cache | 64 | | thread_cache_size | 8 | +------------------------------+------------+ </code></pre> <p>14 rows in set (0.00 sec)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload