{"id":2151,"date":"2005-07-07T21:56:00","date_gmt":"2005-07-07T21:56:00","guid":{"rendered":"http:\/\/www.flubu.com\/blog\/2005\/07\/07\/on-the-value-of-database-indexes\/"},"modified":"2005-07-07T21:56:00","modified_gmt":"2005-07-07T21:56:00","slug":"on-the-value-of-database-indexes","status":"publish","type":"post","link":"https:\/\/www.flubu.com\/blog\/2005\/07\/07\/on-the-value-of-database-indexes\/","title":{"rendered":"On the value of database indexes"},"content":{"rendered":"<p>Been trying to wrap my head around a bug at work, why a simple database query never returned a result set and crashed the server. The query is a simple left join from a &#8220;term&#8221; table with 40K records to a &#8220;term_synonym&#8221; table with 140K records. It should be straightforward. It should work. <\/p>\n<p>It didn&apos;t.<\/p>\n<p>For a very, very stupid reason on my part. <\/p>\n<p>I&apos;d forgotten to create indexes on the tables and it was doing full table scans. That comes out to 5,600,000,000 iterations over the term_synonym table. No wonder it was slow.<\/p>\n<p>After creating the index: <\/p>\n<pre>\nmysql> select count(*) from term t left join term_synonym ts on  t.term_id = ts.term_id;\n+----------+\n| count(*) |\n+----------+\n|   156746 |\n+----------+\n1 row in set (1.72 sec)<\/pre>\n<p>Um, ya, I suck.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Been trying to wrap my head around a bug at work, why a simple database query never returned a result set and crashed the server. The query is a simple left join from a &#8220;term&#8221; table with 40K records to a &#8220;term_synonym&#8221; table with 140K records. It should be straightforward. It should work. It didn&apos;t&#8230;.<\/p>\n<p class=\"more-link-wrap\"><a href=\"https:\/\/www.flubu.com\/blog\/2005\/07\/07\/on-the-value-of-database-indexes\/\" class=\"more-link\">Read More<span class=\"screen-reader-text\"> &ldquo;On the value of database indexes&rdquo;<\/span> &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1],"tags":[17],"class_list":["post-2151","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-geek"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3u9vK-yH","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.flubu.com\/blog\/wp-json\/wp\/v2\/posts\/2151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.flubu.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.flubu.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.flubu.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.flubu.com\/blog\/wp-json\/wp\/v2\/comments?post=2151"}],"version-history":[{"count":0,"href":"https:\/\/www.flubu.com\/blog\/wp-json\/wp\/v2\/posts\/2151\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.flubu.com\/blog\/wp-json\/wp\/v2\/media?parent=2151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.flubu.com\/blog\/wp-json\/wp\/v2\/categories?post=2151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.flubu.com\/blog\/wp-json\/wp\/v2\/tags?post=2151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}