Forums / General Questions / Requesting two rows of data generates almost 100 extra queries?

Requesting two rows of data generates almost 100 extra queries?

Locked

Views: 584

Results 1 to 4 of 4
This thread is locked. New replies are disabled.
14 Nov 2009, 9:16 PM
#1
kiddo avatar

kiddo

Totally Zenned

Join Date:
Jul 2006
Location:
SF Bay Area
Posts:
837
Plugin Contributions:
1

Requesting two rows of data generates almost 100 extra queries?

Looking at the query log dosent seem right, or am I missing something?

When I execute this code:

		$md_sql = "select * from m_data where md_ID = " . $master_ID;

		$movie_data = $db->Execute($md_sql);

		if ($movie_data->RecordCount() > 0)
			{
			while (!$movie_data->EOF)
				{
				echo '<p>Title: ' . $movie_data->fields['md_title'] . '</p>';
				$movie_data->MoveNext();
 		 		}
			}

it returns two records from a table that has only 7 records in it, yet the #of queries reported jumps from 336 to 423

Does it really take 87 queries to select two records out of seven? Or is the way the queries are counted wrong? Or am I doing something wrong?

Yes, the table is properly indexed.

If it's true, is there any way to make this more reasonable?

15 Nov 2009, 2:46 AM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Requesting two rows of data generates almost 100 extra queries?

I think you're doing something wrong with how you're structuring the use of your custom code ... perhaps you've got your query stuck in the middle of a loop, thus causing it to run multiple times.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

15 Nov 2009, 3:14 AM
#3
kiddo avatar

kiddo

Totally Zenned

Join Date:
Jul 2006
Location:
SF Bay Area
Posts:
837
Plugin Contributions:
1

Re: Requesting two rows of data generates almost 100 extra queries?

Well, if it was looping and executing more than once, the test-echo stmnt would fire in each iteration through the loop and make the problem obvious.

Its copied almost verbatim from the example in the wiki with the exception of the table/field names.

The snippit in question executes in includes/modules/pages/product_info/main_template_vars.php to pull in some data from an additional table in the ZC database.

It runs immediately after the main select at about line 46-ish

If it matters, it does return the expected data. The echo stmnt is just for testing.

The results have me worried as this table will eventually contain ~100,000 rows.

Would it be more efficient to just use $result=mysql_query(...)?

Thanks for your expert eye.

15 Nov 2009, 3:32 AM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Requesting two rows of data generates almost 100 extra queries?

The code you posted is just one single query. Unless you've done other changes which you've not mentioned.

Anything else that's changing must be related to other things happening on the page ... perhaps you have a New Products box enabled, and certain products are on sale but others aren't, and when the ones on-sale appear they require additional queries to calculate/display appropriate details, etc.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.