<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Rebuilding Search Index: Performance Results</title>
	<atom:link href="http://www.phpbbdoctor.com/blog/2007/03/04/rebuilding-search-index-performance-results/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.phpbbdoctor.com/blog/2007/03/04/rebuilding-search-index-performance-results/</link>
	<description>Your premium source for custom modification services for phpBB</description>
	<lastBuildDate>Wed, 11 Jan 2012 20:39:04 -0600</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: dave.rathbun</title>
		<link>http://www.phpbbdoctor.com/blog/2007/03/04/rebuilding-search-index-performance-results/comment-page-1/#comment-2214</link>
		<dc:creator>dave.rathbun</dc:creator>
		<pubDate>Sat, 17 Mar 2007 02:35:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpbbdoctor.com/blog/?p=98#comment-2214</guid>
		<description>Do that, please. At some point I will look at the indexing scheme, but I suspect that breaking things into two queries will help.</description>
		<content:encoded><![CDATA[<p>Do that, please. At some point I will look at the indexing scheme, but I suspect that breaking things into two queries will help.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Esmond Poynton</title>
		<link>http://www.phpbbdoctor.com/blog/2007/03/04/rebuilding-search-index-performance-results/comment-page-1/#comment-2206</link>
		<dc:creator>Esmond Poynton</dc:creator>
		<pubDate>Fri, 16 Mar 2007 18:49:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpbbdoctor.com/blog/?p=98#comment-2206</guid>
		<description>Dave,

Thanks for taking the time to have a look. I will do some benchmarking and post the results.</description>
		<content:encoded><![CDATA[<p>Dave,</p>
<p>Thanks for taking the time to have a look. I will do some benchmarking and post the results.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dave.rathbun</title>
		<link>http://www.phpbbdoctor.com/blog/2007/03/04/rebuilding-search-index-performance-results/comment-page-1/#comment-2201</link>
		<dc:creator>dave.rathbun</dc:creator>
		<pubDate>Fri, 16 Mar 2007 17:18:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpbbdoctor.com/blog/?p=98#comment-2201</guid>
		<description>Esmond, I corrected the formatting. :-) Wordpress uses html rather than bbcode, so if you want something bold use &lt;strong&gt; &lt;/strong&gt; and for code the best option seems to be &lt;pre&gt;&lt;/pre&gt;.

I haven&#039;t had a chance to look over this in detail yet, but there is one flaw in the code that may or may not have an impact on performance. It&#039;s a common error on MySQL databases. When you create a query with an aggregate function (like sum() as you have) then you need to have every non-aggregate column appear in the GROUP BY. I will have to post more about that in a blog post. MySQL allows you to be &quot;sloppy&quot; and get away with not doing that, but it can have an impact on your data.

Also, you are doing sum(x) + sum(y) where both x and y come from the same table. I would think that sum(x+y) could be slightly more efficient, although it won&#039;t change your index usage.

Final question: there is no &quot;where clause&quot; other than the expected joins. I believe you said that this was to get the top five cars with the most dollars spent on mods, right? What I would do is get those first in a separate query, retrieve the five vehicle IDs from that query, then go back and do the second query to get just those five.

Here&#039;s why I think two queries is more efficient than one in this case. First, when you have a group by (even an incomplete one ;-)) the entire query has to run to completion before the first row can come back. That means that all of your joins are being done for every car in your database, even though you only want five.

I would do this:
&lt;pre&gt;SELECT	m.vehicle_id,
	SUM(m.install_price + m.price) AS POI,
FROM (
	phpbb_garage_modifications m
)
GROUP BY m.vehicle_id
ORDER BY POI DESC
LIMIT 5&lt;/pre&gt;
That query should run much faster than the larger query that you have. It will return a dataset of five car id values. Next, replace your bigger query with this:
&lt;pre&gt;SELECT v.id,
	CONCAT_WS(&#039; &#039;, v.made_year, mk.make, md.model) AS vehicle,
	v.user_id,
	u.username,
	v.currency,
	u.user_colour,
	u.user_id
FROM (
	phpbb_garage_vehicles v,
	phpbb_garage_makes mk,
	phpbb_garage_models md,
	phpbb_users u
)
WHERE	v.id IN ( ... insert ids from prior query here ... )
	AND v.make_id = mk.id
	AND mk.pending = 0
	AND v.model_id = md.id
	AND md.pending = 0
	AND v.user_id = u.user_id&lt;/pre&gt;
You will notice that I skipped the &quot;modifications&quot; table in the second query. You have the total modification dollars (currency type) already from the prior query, so you don&#039;t need to have the overhead of recalculating it in this query.

The net result - without any benchmarking on my part, I should add - should be an improvement, I would think. The first query still runs a GROUP BY and a SUM but only on one table. No joins are required. From that query you will get a dataset (array) of vehicle ID values and their total modification dollars. The second query gets the user and vehicle specifics for those top 5 vehicles.</description>
		<content:encoded><![CDATA[<p>Esmond, I corrected the formatting. <img src='http://www.phpbbdoctor.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  Wordpress uses html rather than bbcode, so if you want something bold use &lt;strong&gt; &lt;/strong&gt; and for code the best option seems to be &lt;pre&gt;&lt;/pre&gt;.</p>
<p>I haven&#8217;t had a chance to look over this in detail yet, but there is one flaw in the code that may or may not have an impact on performance. It&#8217;s a common error on MySQL databases. When you create a query with an aggregate function (like sum() as you have) then you need to have every non-aggregate column appear in the GROUP BY. I will have to post more about that in a blog post. MySQL allows you to be &#8220;sloppy&#8221; and get away with not doing that, but it can have an impact on your data.</p>
<p>Also, you are doing sum(x) + sum(y) where both x and y come from the same table. I would think that sum(x+y) could be slightly more efficient, although it won&#8217;t change your index usage.</p>
<p>Final question: there is no &#8220;where clause&#8221; other than the expected joins. I believe you said that this was to get the top five cars with the most dollars spent on mods, right? What I would do is get those first in a separate query, retrieve the five vehicle IDs from that query, then go back and do the second query to get just those five.</p>
<p>Here&#8217;s why I think two queries is more efficient than one in this case. First, when you have a group by (even an incomplete one <img src='http://www.phpbbdoctor.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ) the entire query has to run to completion before the first row can come back. That means that all of your joins are being done for every car in your database, even though you only want five.</p>
<p>I would do this:</p>
<pre>SELECT	m.vehicle_id,
	SUM(m.install_price + m.price) AS POI,
FROM (
	phpbb_garage_modifications m
)
GROUP BY m.vehicle_id
ORDER BY POI DESC
LIMIT 5</pre>
<p>That query should run much faster than the larger query that you have. It will return a dataset of five car id values. Next, replace your bigger query with this:</p>
<pre>SELECT v.id,
	CONCAT_WS(' ', v.made_year, mk.make, md.model) AS vehicle,
	v.user_id,
	u.username,
	v.currency,
	u.user_colour,
	u.user_id
FROM (
	phpbb_garage_vehicles v,
	phpbb_garage_makes mk,
	phpbb_garage_models md,
	phpbb_users u
)
WHERE	v.id IN ( ... insert ids from prior query here ... )
	AND v.make_id = mk.id
	AND mk.pending = 0
	AND v.model_id = md.id
	AND md.pending = 0
	AND v.user_id = u.user_id</pre>
<p>You will notice that I skipped the &#8220;modifications&#8221; table in the second query. You have the total modification dollars (currency type) already from the prior query, so you don&#8217;t need to have the overhead of recalculating it in this query.</p>
<p>The net result &#8211; without any benchmarking on my part, I should add &#8211; should be an improvement, I would think. The first query still runs a GROUP BY and a SUM but only on one table. No joins are required. From that query you will get a dataset (array) of vehicle ID values and their total modification dollars. The second query gets the user and vehicle specifics for those top 5 vehicles.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Esmond Poynton</title>
		<link>http://www.phpbbdoctor.com/blog/2007/03/04/rebuilding-search-index-performance-results/comment-page-1/#comment-1979</link>
		<dc:creator>Esmond Poynton</dc:creator>
		<pubDate>Tue, 06 Mar 2007 14:21:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpbbdoctor.com/blog/?p=98#comment-1979</guid>
		<description>OK...here goes!! Hope the formatting works :) &lt;em&gt;(edited to correct formatting, Wordpress uses html rather than bbcode. - Dave)&lt;/em&gt;

This query is to get vehicles with the most money spent on them. 
Vehicles are stored in phpbb_garage_vehicles. Each vehicle can have lots of modifications, each modification is stored in phpbb_garage_modifications. Each modification has two &quot;costs&quot; associated with them, a purchase and install price. We need to get the sum of these and return the vehicles with the highest sum. Each vehicle is own by one user stored in the regular table and each vehicle consists of a make and a model stored in table phpbb_garage_makes &amp; phpbb_garage_models

Hope that makes sense. Query is as below.

&lt;pre&gt;SELECT v.id, 
	CONCAT_WS(&#039; &#039;, v.made_year, mk.make, md.model) AS vehicle, 
	v.user_id, 
	(SUM(m.install_price) + SUM(m.price)) AS POI, 
	u.username, 
	v.currency, 
	u.user_colour, 
	u.user_id 
FROM (
	phpbb_garage_vehicles v,
	phpbb_garage_makes mk,
	phpbb_garage_models md,
	phpbb_users u,
	phpbb_garage_modifications m
) 
WHERE m.vehicle_id = v.id
	AND v.make_id = mk.id 
	AND mk.pending = 0
	AND v.model_id = md.id 
	AND md.pending = 0
	AND v.user_id = u.user_id 
GROUP BY v.id
ORDER BY POI DESC
LIMIT 5&lt;/pre&gt;

So our explain plan gives us the follow. We can see we have &quot;using temporary&quot;, which all my reading I believe to be a indicator of poor index/query structure.

&lt;pre&gt;
+-----+---------------+----------+------------+-----------------------------+---------+---------+----------------------+-------+----------------------------------+
&#124;  Id &#124;   Select Type &#124;   Table  &#124;    Type    &#124;       Possible Keys         &#124;   Key   &#124;  KeyLen	&#124;         Ref          &#124;  Rows &#124;      Extra                       &#124;
+-----+---------------+----------+------------+-----------------------------+---------+---------+----------------------+-------+----------------------------------+
&#124;  1  &#124;     SIMPLE    &#124;     m    &#124;     ALL    &#124;	vehicle_id_2,vehicle_id     &#124;         &#124;         &#124;                      &#124;   3   &#124;  Using temporary; Using filesort &#124;
&#124;  1  &#124;     SIMPLE    &#124;     v    &#124;    eq_ref  &#124;	PRIMARY,user_id             &#124; PRIMARY &#124;    4    &#124; phpbb3.m.vehicle_id  &#124;   1   &#124;                                  &#124;
&#124;  1  &#124;     SIMPLE    &#124;     u    &#124;    eq_ref  &#124;	PRIMARY                     &#124; PRIMARY &#124;    3    &#124; phpbb3.v.user_id     &#124;   1   &#124;  Using where                     &#124;
&#124;  1  &#124;     SIMPLE    &#124;     mk   &#124;    eq_ref  &#124;	PRIMARY                     &#124; PRIMARY &#124;    4    &#124; phpbb3.v.make_id     &#124;   1   &#124;  Using where                     &#124;
&#124;  1  &#124;     SIMPLE    &#124;     md   &#124;    eq_ref  &#124;	PRIMARY                     &#124; PRIMARY &#124;    4    &#124; phpbb3.v.model_id    &#124;   1   &#124;  Using where                     &#124;
+-----+---------------+----------+------------+-----------------------------+---------+---------+----------------------+-------+----------------------------------+&lt;/pre&gt;

So we have 5 table involved and we have the following structure, I will not bother listing phpbb_users as you know that one!! ;)

&lt;strong&gt;Table description for phpbb_garage_vehicles&lt;/strong&gt;
&lt;pre&gt;+------------------+----------------------------+---------+-------+---------------+----------------+
+  Field           &#124;              Type          &#124;   Null  &#124;  Key  &#124; Default       &#124;    Extra       &#124;
+------------------+----------------------------+---------+-------+---------------+----------------+
&#124; id               &#124; int(10) unsigned           &#124;   NO    &#124;  PRI  &#124; 	NULL      &#124; auto_increment &#124;
&#124; user_id          &#124; int(10)                    &#124;   NO    &#124;  MUL  &#124; 	0         &#124;                &#124;
&#124; made_year        &#124; varchar(4)                 &#124;   NO    &#124;       &#124;     2003      &#124;                &#124;
&#124; engine_type      &#124; varchar(32)                &#124;   NO    &#124;       &#124;     NULL      &#124;                &#124;
&#124; colour           &#124; varchar(128)               &#124;   YES   &#124;       &#124;     NULL      &#124;                &#124;
&#124; mileage          &#124; int(10) unsigned           &#124;   NO    &#124;       &#124;     0         &#124;                &#124;
&#124; mileage_unit     &#124; varchar(32)                &#124;   NO    &#124;       &#124;     Miles     &#124;                &#124;
&#124; price            &#124; int(10) unsigned           &#124;   YES   &#124;       &#124;     NULL      &#124;                &#124;
&#124; currency         &#124; varchar(32)                &#124;   NO    &#124;       &#124;     USD       &#124;                &#124;
&#124; comments         &#124; varchar(255)               &#124;   YES   &#124;       &#124;     NULL      &#124;                &#124;
&#124; views            &#124; int(10) unsigned           &#124;   NO    &#124;  MUL 	&#124;     0         &#124;                &#124;
&#124; date_created     &#124; int(10)                    &#124;   YES   &#124;  MUL  &#124; 	NULL      &#124;                &#124;
&#124; date_updated     &#124; int(10)                    &#124;   YES   &#124;  MUL 	&#124;     NULL      &#124;                &#124;
&#124; make_id          &#124; int(10) unsigned           &#124;   NO    &#124;       &#124;     0         &#124;                &#124;
&#124; model_id         &#124; int(10) unsigned           &#124;   NO    &#124;       &#124;     0         &#124;                &#124;
&#124; main_vehicle     &#124; tinyint(1)                 &#124;   NO    &#124;       &#124;     0         &#124;                &#124;
&#124; weighted_rating  &#124; double                     &#124;   NO    &#124;       &#124;     0         &#124;                &#124;
&#124; pending          &#124; tinyint(1)                 &#124;   NO    &#124;       &#124;     0         &#124;                &#124;
+------------------+----------------------------+---------+-------+---------------+----------------+&lt;/pre&gt;

&lt;strong&gt;Indexes for phpbb_garage_vehicles&lt;/strong&gt;
&lt;pre&gt;+---------------+----------+-------------------+--------------------------------+
&#124;    Keyname    &#124;   Type   &#124;    Cardinality    &#124;  Field                         &#124;
+---------------+----------+-------------------+--------------------------------+
&#124; PRIMARY       &#124; PRIMARY  &#124;  3                &#124; id                             &#124;
&#124; date_created  &#124; INDEX    &#124;  None             &#124; date_created                   &#124;
&#124; date_updated  &#124; INDEX    &#124;  None             &#124; date_updated                   &#124;
&#124; user_id       &#124; INDEX    &#124;  None             &#124; user_id                        &#124;
&#124; views         &#124; INDEX    &#124;  None             &#124; views                          &#124;
+---------------+----------+-------------------+--------------------------------+&lt;/pre&gt;

&lt;strong&gt;Table description for phpbb_garage_makes&lt;/strong&gt;
&lt;pre&gt;+------------------+----------------------------+-------------+-------+---------------+----------------+
+  Field           &#124;              Type          &#124;    Null     &#124;  Key  &#124; Default       &#124;    Extra       &#124;
+------------------+----------------------------+-------------+-------+---------------+----------------+
&#124; id               &#124; int(10) unsigned           &#124; NO          &#124;  PRI  &#124; NULL          &#124; auto_increment &#124;
&#124; make             &#124; varchar(255)               &#124; NO          &#124;  MUL  &#124;               &#124;                &#124; 	  	 
&#124; pending          &#124; tinyint(1)                 &#124; NO          &#124;       &#124; 1             &#124;                &#124;
+------------------+----------------------------+-------------+-------+---------------+----------------+&lt;/pre&gt;

&lt;strong&gt;Indexes for phpbb_garage_makes&lt;/strong&gt;
&lt;pre&gt;+---------------+----------+-------------------+--------------------------------+
&#124;    Keyname    &#124;   Type   &#124;    Cardinality    &#124;  Field                         &#124;
+---------------+----------+-------------------+--------------------------------+
&#124; PRIMARY       &#124; PRIMARY  &#124;  91               &#124;  id                            &#124;
&#124; make          &#124; INDEX    &#124;  None             &#124;  make                          &#124;
+---------------+----------+-------------------+--------------------------------+&lt;/pre&gt;

&lt;strong&gt;Table description for phpbb_garage_models&lt;/strong&gt;
&lt;pre&gt;+------------------+----------------------------+-------------+-------+---------------+----------------+
+  Field           &#124;              Type          &#124;    Null     &#124;  Key  &#124; Default       &#124;    Extra       &#124;
+------------------+----------------------------+-------------+-------+---------------+----------------+
&#124; id               &#124; int(10) unsigned           &#124;  NO         &#124;  PRI  &#124; NULL          &#124; auto_increment &#124;
&#124; make_id          &#124; int(10) unsigned           &#124;  NO         &#124;  MUL  &#124; 0             &#124;                &#124;
&#124; model            &#124; varchar(255)               &#124;  NO         &#124;       &#124;               &#124;                &#124;
&#124; pending          &#124; tinyint(1)                 &#124;  NO         &#124;       &#124; 1             &#124;                &#124;
+------------------+----------------------------+-------------+-------+---------------+----------------+&lt;/pre&gt;

&lt;strong&gt;Indexes for phpbb_garage_models&lt;/strong&gt;
&lt;pre&gt;+---------------+----------+-------------------+--------------------------------+
&#124;    Keyname    &#124;   Type   &#124;    Cardinality    &#124;  Field                         &#124;
+---------------+----------+-------------------+--------------------------------+
&#124;    PRIMARY    &#124;  PRIMARY &#124;        811        &#124; id                             &#124;
&#124;    make_id    &#124;  INDEX   &#124;        None       &#124; make_id                        &#124;
+---------------+----------+-------------------+--------------------------------+&lt;/pre&gt;

&lt;strong&gt;Table description for phpbb_garage_modifications&lt;/strong&gt;
&lt;pre&gt;+------------------+----------------------------+-------------+-------+---------------+----------------+
+  Field           &#124;              Type          &#124;    Null     &#124;  Key  &#124; Default       &#124;    Extra       &#124;
+------------------+----------------------------+-------------+-------+---------------+----------------+
&#124; id               &#124; int(10) unsigned           &#124;     NO      &#124;  PRI  &#124; NULL          &#124; auto_increment &#124;
&#124; vehicle_id       &#124; int(10) unsigned           &#124;     NO      &#124;  MUL  &#124; 0             &#124;                &#124;
&#124; user_id          &#124; int(10)                    &#124;     NO      &#124;  MUL  &#124; 0             &#124;                &#124;
&#124; category_id      &#124; int(10) unsigned           &#124;     NO      &#124;  MUL  &#124; 0             &#124;                &#124;
&#124; manufacturer_id  &#124; int(10) unsigned           &#124;     NO      &#124;       &#124; 0             &#124;                &#124;
&#124; product_id       &#124; int(10) unsigned           &#124;     NO      &#124;       &#124; 0             &#124;                &#124;
&#124; price            &#124; int(10) unsigned           &#124;     NO      &#124;       &#124; 0             &#124;                &#124;
&#124; install_price    &#124; int(10) unsigned           &#124;     NO      &#124;       &#124; 0             &#124;                &#124;
&#124; product_rating   &#124; tinyint(2)                 &#124;     YES     &#124;       &#124; NULL          &#124;                &#124;
&#124; purchase_rating  &#124; tinyint(2)                 &#124;     YES     &#124;       &#124; NULL          &#124;                &#124;
&#124; install_rating   &#124; tinyint(2)                 &#124;     YES     &#124;       &#124; NULL          &#124;                &#124;
&#124; shop_id          &#124; int(10)                    &#124;     YES     &#124;       &#124; NULL          &#124;                &#124;
&#124; installer_id     &#124; int(10)                    &#124;     YES     &#124;       &#124; NULL          &#124;                &#124;
&#124; comments         &#124; text                       &#124;     YES     &#124;       &#124; NULL          &#124;                &#124;
&#124; install_comments &#124; text                       &#124;     YES     &#124;       &#124; NULL          &#124;                &#124;
&#124; date_created     &#124; int(10)                    &#124;     YES     &#124;  MUL  &#124; NULL          &#124;                &#124;
&#124; date_updated     &#124; int(10)                    &#124;     YES     &#124;  MUL  &#124; NULL          &#124;                &#124;
+------------------+----------------------------+-------------+-------+---------------+----------------+&lt;/pre&gt;

&lt;strong&gt;Indexes for phpbb_garage_modifications&lt;/strong&gt;
&lt;pre&gt;+---------------+----------+-------------------+--------------------------------+
&#124;    Keyname    &#124;   Type   &#124;    Cardinality    &#124;  Field                         &#124;
+---------------+----------+-------------------+--------------------------------+
&#124; PRIMARY       &#124; PRIMARY  &#124; 3                 &#124; id                             &#124;
&#124; user_id       &#124; INDEX    &#124; None              &#124; user_id                        &#124;
&#124; vehicle_id_2  &#124; INDEX    &#124; None              &#124; vehicle_id, category_id        &#124;
&#124; category_id   &#124; INDEX    &#124; None              &#124; category_id                    &#124;
&#124; vehicle_id    &#124; INDEX    &#124; None              &#124; vehicle_id                     &#124;
&#124; date_created  &#124; INDEX    &#124; None              &#124; date_created                   &#124;
&#124; date_updated  &#124; INDEX    &#124; None              &#124; date_updated                   &#124;
+---------------+----------+-------------------+--------------------------------+&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>OK&#8230;here goes!! Hope the formatting works <img src='http://www.phpbbdoctor.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  <em>(edited to correct formatting, Wordpress uses html rather than bbcode. &#8211; Dave)</em></p>
<p>This query is to get vehicles with the most money spent on them.<br />
Vehicles are stored in phpbb_garage_vehicles. Each vehicle can have lots of modifications, each modification is stored in phpbb_garage_modifications. Each modification has two &#8220;costs&#8221; associated with them, a purchase and install price. We need to get the sum of these and return the vehicles with the highest sum. Each vehicle is own by one user stored in the regular table and each vehicle consists of a make and a model stored in table phpbb_garage_makes &amp; phpbb_garage_models</p>
<p>Hope that makes sense. Query is as below.</p>
<pre>SELECT v.id,
	CONCAT_WS(' ', v.made_year, mk.make, md.model) AS vehicle,
	v.user_id,
	(SUM(m.install_price) + SUM(m.price)) AS POI,
	u.username,
	v.currency,
	u.user_colour,
	u.user_id
FROM (
	phpbb_garage_vehicles v,
	phpbb_garage_makes mk,
	phpbb_garage_models md,
	phpbb_users u,
	phpbb_garage_modifications m
)
WHERE m.vehicle_id = v.id
	AND v.make_id = mk.id
	AND mk.pending = 0
	AND v.model_id = md.id
	AND md.pending = 0
	AND v.user_id = u.user_id
GROUP BY v.id
ORDER BY POI DESC
LIMIT 5</pre>
<p>So our explain plan gives us the follow. We can see we have &#8220;using temporary&#8221;, which all my reading I believe to be a indicator of poor index/query structure.</p>
<pre>
+-----+---------------+----------+------------+-----------------------------+---------+---------+----------------------+-------+----------------------------------+
|  Id |   Select Type |   Table  |    Type    |       Possible Keys         |   Key   |  KeyLen	|         Ref          |  Rows |      Extra                       |
+-----+---------------+----------+------------+-----------------------------+---------+---------+----------------------+-------+----------------------------------+
|  1  |     SIMPLE    |     m    |     ALL    |	vehicle_id_2,vehicle_id     |         |         |                      |   3   |  Using temporary; Using filesort |
|  1  |     SIMPLE    |     v    |    eq_ref  |	PRIMARY,user_id             | PRIMARY |    4    | phpbb3.m.vehicle_id  |   1   |                                  |
|  1  |     SIMPLE    |     u    |    eq_ref  |	PRIMARY                     | PRIMARY |    3    | phpbb3.v.user_id     |   1   |  Using where                     |
|  1  |     SIMPLE    |     mk   |    eq_ref  |	PRIMARY                     | PRIMARY |    4    | phpbb3.v.make_id     |   1   |  Using where                     |
|  1  |     SIMPLE    |     md   |    eq_ref  |	PRIMARY                     | PRIMARY |    4    | phpbb3.v.model_id    |   1   |  Using where                     |
+-----+---------------+----------+------------+-----------------------------+---------+---------+----------------------+-------+----------------------------------+</pre>
<p>So we have 5 table involved and we have the following structure, I will not bother listing phpbb_users as you know that one!! <img src='http://www.phpbbdoctor.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><strong>Table description for phpbb_garage_vehicles</strong></p>
<pre>+------------------+----------------------------+---------+-------+---------------+----------------+
+  Field           |              Type          |   Null  |  Key  | Default       |    Extra       |
+------------------+----------------------------+---------+-------+---------------+----------------+
| id               | int(10) unsigned           |   NO    |  PRI  | 	NULL      | auto_increment |
| user_id          | int(10)                    |   NO    |  MUL  | 	0         |                |
| made_year        | varchar(4)                 |   NO    |       |     2003      |                |
| engine_type      | varchar(32)                |   NO    |       |     NULL      |                |
| colour           | varchar(128)               |   YES   |       |     NULL      |                |
| mileage          | int(10) unsigned           |   NO    |       |     0         |                |
| mileage_unit     | varchar(32)                |   NO    |       |     Miles     |                |
| price            | int(10) unsigned           |   YES   |       |     NULL      |                |
| currency         | varchar(32)                |   NO    |       |     USD       |                |
| comments         | varchar(255)               |   YES   |       |     NULL      |                |
| views            | int(10) unsigned           |   NO    |  MUL 	|     0         |                |
| date_created     | int(10)                    |   YES   |  MUL  | 	NULL      |                |
| date_updated     | int(10)                    |   YES   |  MUL 	|     NULL      |                |
| make_id          | int(10) unsigned           |   NO    |       |     0         |                |
| model_id         | int(10) unsigned           |   NO    |       |     0         |                |
| main_vehicle     | tinyint(1)                 |   NO    |       |     0         |                |
| weighted_rating  | double                     |   NO    |       |     0         |                |
| pending          | tinyint(1)                 |   NO    |       |     0         |                |
+------------------+----------------------------+---------+-------+---------------+----------------+</pre>
<p><strong>Indexes for phpbb_garage_vehicles</strong></p>
<pre>+---------------+----------+-------------------+--------------------------------+
|    Keyname    |   Type   |    Cardinality    |  Field                         |
+---------------+----------+-------------------+--------------------------------+
| PRIMARY       | PRIMARY  |  3                | id                             |
| date_created  | INDEX    |  None             | date_created                   |
| date_updated  | INDEX    |  None             | date_updated                   |
| user_id       | INDEX    |  None             | user_id                        |
| views         | INDEX    |  None             | views                          |
+---------------+----------+-------------------+--------------------------------+</pre>
<p><strong>Table description for phpbb_garage_makes</strong></p>
<pre>+------------------+----------------------------+-------------+-------+---------------+----------------+
+  Field           |              Type          |    Null     |  Key  | Default       |    Extra       |
+------------------+----------------------------+-------------+-------+---------------+----------------+
| id               | int(10) unsigned           | NO          |  PRI  | NULL          | auto_increment |
| make             | varchar(255)               | NO          |  MUL  |               |                |
| pending          | tinyint(1)                 | NO          |       | 1             |                |
+------------------+----------------------------+-------------+-------+---------------+----------------+</pre>
<p><strong>Indexes for phpbb_garage_makes</strong></p>
<pre>+---------------+----------+-------------------+--------------------------------+
|    Keyname    |   Type   |    Cardinality    |  Field                         |
+---------------+----------+-------------------+--------------------------------+
| PRIMARY       | PRIMARY  |  91               |  id                            |
| make          | INDEX    |  None             |  make                          |
+---------------+----------+-------------------+--------------------------------+</pre>
<p><strong>Table description for phpbb_garage_models</strong></p>
<pre>+------------------+----------------------------+-------------+-------+---------------+----------------+
+  Field           |              Type          |    Null     |  Key  | Default       |    Extra       |
+------------------+----------------------------+-------------+-------+---------------+----------------+
| id               | int(10) unsigned           |  NO         |  PRI  | NULL          | auto_increment |
| make_id          | int(10) unsigned           |  NO         |  MUL  | 0             |                |
| model            | varchar(255)               |  NO         |       |               |                |
| pending          | tinyint(1)                 |  NO         |       | 1             |                |
+------------------+----------------------------+-------------+-------+---------------+----------------+</pre>
<p><strong>Indexes for phpbb_garage_models</strong></p>
<pre>+---------------+----------+-------------------+--------------------------------+
|    Keyname    |   Type   |    Cardinality    |  Field                         |
+---------------+----------+-------------------+--------------------------------+
|    PRIMARY    |  PRIMARY |        811        | id                             |
|    make_id    |  INDEX   |        None       | make_id                        |
+---------------+----------+-------------------+--------------------------------+</pre>
<p><strong>Table description for phpbb_garage_modifications</strong></p>
<pre>+------------------+----------------------------+-------------+-------+---------------+----------------+
+  Field           |              Type          |    Null     |  Key  | Default       |    Extra       |
+------------------+----------------------------+-------------+-------+---------------+----------------+
| id               | int(10) unsigned           |     NO      |  PRI  | NULL          | auto_increment |
| vehicle_id       | int(10) unsigned           |     NO      |  MUL  | 0             |                |
| user_id          | int(10)                    |     NO      |  MUL  | 0             |                |
| category_id      | int(10) unsigned           |     NO      |  MUL  | 0             |                |
| manufacturer_id  | int(10) unsigned           |     NO      |       | 0             |                |
| product_id       | int(10) unsigned           |     NO      |       | 0             |                |
| price            | int(10) unsigned           |     NO      |       | 0             |                |
| install_price    | int(10) unsigned           |     NO      |       | 0             |                |
| product_rating   | tinyint(2)                 |     YES     |       | NULL          |                |
| purchase_rating  | tinyint(2)                 |     YES     |       | NULL          |                |
| install_rating   | tinyint(2)                 |     YES     |       | NULL          |                |
| shop_id          | int(10)                    |     YES     |       | NULL          |                |
| installer_id     | int(10)                    |     YES     |       | NULL          |                |
| comments         | text                       |     YES     |       | NULL          |                |
| install_comments | text                       |     YES     |       | NULL          |                |
| date_created     | int(10)                    |     YES     |  MUL  | NULL          |                |
| date_updated     | int(10)                    |     YES     |  MUL  | NULL          |                |
+------------------+----------------------------+-------------+-------+---------------+----------------+</pre>
<p><strong>Indexes for phpbb_garage_modifications</strong></p>
<pre>+---------------+----------+-------------------+--------------------------------+
|    Keyname    |   Type   |    Cardinality    |  Field                         |
+---------------+----------+-------------------+--------------------------------+
| PRIMARY       | PRIMARY  | 3                 | id                             |
| user_id       | INDEX    | None              | user_id                        |
| vehicle_id_2  | INDEX    | None              | vehicle_id, category_id        |
| category_id   | INDEX    | None              | category_id                    |
| vehicle_id    | INDEX    | None              | vehicle_id                     |
| date_created  | INDEX    | None              | date_created                   |
| date_updated  | INDEX    | None              | date_updated                   |
+---------------+----------+-------------------+--------------------------------+</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: dave.rathbun</title>
		<link>http://www.phpbbdoctor.com/blog/2007/03/04/rebuilding-search-index-performance-results/comment-page-1/#comment-1958</link>
		<dc:creator>dave.rathbun</dc:creator>
		<pubDate>Tue, 06 Mar 2007 08:16:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpbbdoctor.com/blog/?p=98#comment-1958</guid>
		<description>That comment was tagged by Akismet also. Fortunately I read them before deleting them. I don&#039;t know what&#039;s going on.

If you care to post a query and the explain plan, along with the index structure for the tables involved, I will be happy to use it as a case study for a future post. 8)</description>
		<content:encoded><![CDATA[<p>That comment was tagged by Akismet also. Fortunately I read them before deleting them. I don&#8217;t know what&#8217;s going on.</p>
<p>If you care to post a query and the explain plan, along with the index structure for the tables involved, I will be happy to use it as a case study for a future post. <img src='http://www.phpbbdoctor.com/blog/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Esmond Poynton</title>
		<link>http://www.phpbbdoctor.com/blog/2007/03/04/rebuilding-search-index-performance-results/comment-page-1/#comment-1956</link>
		<dc:creator>Esmond Poynton</dc:creator>
		<pubDate>Tue, 06 Mar 2007 07:57:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpbbdoctor.com/blog/?p=98#comment-1956</guid>
		<description>Think I only made that one post :-? 
Looking forward to the upcoming posts. Doing some reading myself on DB design and queries, as my MOD has a few queries &quot;using temporary&quot; in the MySQL extra explain. So maybe a post on where index&#039;s should be created would be good.</description>
		<content:encoded><![CDATA[<p>Think I only made that one post <img src='http://www.phpbbdoctor.com/blog/wp-includes/images/smilies/icon_confused.gif' alt=':-?' class='wp-smiley' /><br />
Looking forward to the upcoming posts. Doing some reading myself on DB design and queries, as my MOD has a few queries &#8220;using temporary&#8221; in the MySQL extra explain. So maybe a post on where index&#8217;s should be created would be good.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dave.rathbun</title>
		<link>http://www.phpbbdoctor.com/blog/2007/03/04/rebuilding-search-index-performance-results/comment-page-1/#comment-1924</link>
		<dc:creator>dave.rathbun</dc:creator>
		<pubDate>Mon, 05 Mar 2007 13:56:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpbbdoctor.com/blog/?p=98#comment-1924</guid>
		<description>Esmond, your last two comments have been marked as spam. :-?

Search synonyms are, in fact, a topic of an upcoming post. They don&#039;t work the way I expected them to. They work, of course, but they&#039;re just different. In my revised code they have also been moved into the database, and they have been given the same treatment. That is to say that after moving them to the database I can then check for synonyms only of the words that are actually in use rather than applying the entire synonym file... even to a post with only one word. :-)

I like the fact that search synonyms can be used to &quot;correct&quot; for words that are commonly spelled wrong.

I had not known who the main developer was for the search process. And thanks for confirming that some of this research might even be appropriate for phpBB3 as well.

I should make one thing very clear: &lt;strong&gt;I like the phpBB2 search process&lt;/strong&gt;. I think that if we could figure out a way to effectively add a &quot;search exact phrase&quot; option to the process it would be awesome. The point of this series of posts has been to justify to detractors why I like the search process ;-) and along the way, as I have discovered things, to document some tweaks that can make it even better.

As far as future posts, I am going to talk about the search synonym process, the &quot;common words&quot; problem, an enhancement to search.php that I&#039;m writing that will help the user understand how to get better search results... and a few more that at the moment I don&#039;t remember. :-) For example we have the concept of search stopwords which I have covered now in great detail, the concept of search synonyms which is coming... I have an idea for a MOD called Search Addwords aka the Jargon MOD. There are certain &quot;words&quot; that get dropped because they are too short (or too long) or structured in such a way that they get ignored. For certain boards it might be vital to search for certain two-letter words, but not &lt;strong&gt;all&lt;/strong&gt; two-letter words. 

I plan to expand on the process of putting search words into the database by creating a MOD that allows board owners to &lt;strong&gt;add words&lt;/strong&gt; that they want to &lt;strong&gt;ensure get included in the search index&lt;/strong&gt;. Those words would likely be very unique to each board. For example, on your board maybe you want people to be able to search for &quot;Mustang V8 GT&quot; or something like that. Well, &lt;strong&gt;GT&lt;/strong&gt; and &lt;strong&gt;V8&lt;/strong&gt; would be ignored because they&#039;re too short. With a Seach Addwords table you could ensure that those words do, in fact, get included in the search index. It seems to be a logical extension of the existing search process; I&#039;m surprised I have not seen it suggested somewhere else before.

Which doesn&#039;t mean that it hasn&#039;t been... it just means I haven&#039;t seen it. :-D

&lt;em&gt;Thanks again for your comment; I wish I knew what you had done to trigger the spam filter. If at some point a comment of yours gets removed, it was an accident and nothing personal. Some times I open the spam list and click &quot;Delete All&quot; without reading through the list; it depends on how many are waiting.&lt;/em&gt;</description>
		<content:encoded><![CDATA[<p>Esmond, your last two comments have been marked as spam. <img src='http://www.phpbbdoctor.com/blog/wp-includes/images/smilies/icon_confused.gif' alt=':-?' class='wp-smiley' /> </p>
<p>Search synonyms are, in fact, a topic of an upcoming post. They don&#8217;t work the way I expected them to. They work, of course, but they&#8217;re just different. In my revised code they have also been moved into the database, and they have been given the same treatment. That is to say that after moving them to the database I can then check for synonyms only of the words that are actually in use rather than applying the entire synonym file&#8230; even to a post with only one word. <img src='http://www.phpbbdoctor.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>I like the fact that search synonyms can be used to &#8220;correct&#8221; for words that are commonly spelled wrong.</p>
<p>I had not known who the main developer was for the search process. And thanks for confirming that some of this research might even be appropriate for phpBB3 as well.</p>
<p>I should make one thing very clear: <strong>I like the phpBB2 search process</strong>. I think that if we could figure out a way to effectively add a &#8220;search exact phrase&#8221; option to the process it would be awesome. The point of this series of posts has been to justify to detractors why I like the search process <img src='http://www.phpbbdoctor.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  and along the way, as I have discovered things, to document some tweaks that can make it even better.</p>
<p>As far as future posts, I am going to talk about the search synonym process, the &#8220;common words&#8221; problem, an enhancement to search.php that I&#8217;m writing that will help the user understand how to get better search results&#8230; and a few more that at the moment I don&#8217;t remember. <img src='http://www.phpbbdoctor.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  For example we have the concept of search stopwords which I have covered now in great detail, the concept of search synonyms which is coming&#8230; I have an idea for a MOD called Search Addwords aka the Jargon MOD. There are certain &#8220;words&#8221; that get dropped because they are too short (or too long) or structured in such a way that they get ignored. For certain boards it might be vital to search for certain two-letter words, but not <strong>all</strong> two-letter words. </p>
<p>I plan to expand on the process of putting search words into the database by creating a MOD that allows board owners to <strong>add words</strong> that they want to <strong>ensure get included in the search index</strong>. Those words would likely be very unique to each board. For example, on your board maybe you want people to be able to search for &#8220;Mustang V8 GT&#8221; or something like that. Well, <strong>GT</strong> and <strong>V8</strong> would be ignored because they&#8217;re too short. With a Seach Addwords table you could ensure that those words do, in fact, get included in the search index. It seems to be a logical extension of the existing search process; I&#8217;m surprised I have not seen it suggested somewhere else before.</p>
<p>Which doesn&#8217;t mean that it hasn&#8217;t been&#8230; it just means I haven&#8217;t seen it. <img src='http://www.phpbbdoctor.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> </p>
<p><em>Thanks again for your comment; I wish I knew what you had done to trigger the spam filter. If at some point a comment of yours gets removed, it was an accident and nothing personal. Some times I open the spam list and click &#8220;Delete All&#8221; without reading through the list; it depends on how many are waiting.</em></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Esmond Poynton</title>
		<link>http://www.phpbbdoctor.com/blog/2007/03/04/rebuilding-search-index-performance-results/comment-page-1/#comment-1921</link>
		<dc:creator>Esmond Poynton</dc:creator>
		<pubDate>Mon, 05 Mar 2007 12:02:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpbbdoctor.com/blog/?p=98#comment-1921</guid>
		<description>Dave,

As always a great post with some very interesting results. Be interesting to hear someone like naderman comment on this type of research. As he seems to be the dev handling searching in phpBB3, and we still have the same concept now called ignore words.

You plan on covering search synonyms at all? I know are used on the query side of the search engine + phpBB ships with some funny ones. My fav being &quot;gynecology gynaecology&quot;, useful for 0.0001% of boards!!</description>
		<content:encoded><![CDATA[<p>Dave,</p>
<p>As always a great post with some very interesting results. Be interesting to hear someone like naderman comment on this type of research. As he seems to be the dev handling searching in phpBB3, and we still have the same concept now called ignore words.</p>
<p>You plan on covering search synonyms at all? I know are used on the query side of the search engine + phpBB ships with some funny ones. My fav being &#8220;gynecology gynaecology&#8221;, useful for 0.0001% of boards!!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

