vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   How to find a bad query (https://vborg.vbsupport.ru/showthread.php?t=35400)

JJR512 02-23-2002 10:00 PM

I've been testing a hack I've been working on. At one point during the testing, I received a MySQL error message stating there was a problem with a query. It said what the query was, but as you've probably noticed in these error messages, it only gives a line number of '1'. The problem here was that I had four of the exact same query throughout the code, and I couldn't tell which one was causing the problem.

The specific problem was that in the WHERE part, it was written like "WHERE field=$variable", and $variable didn't have a value. The problem really wasn't the query itself, it was the code before it that was supposed to generate a value for $variable.

So the problem was how to quickly find out which of the four identical queries had some bad code before it. Then I realized how to do it. In the first query, I put a "and 1=1" at the end of the WHERE part, so it was like "WHERE field=$variable and 1=1". For the next one, I did 2=2, and so on, for all four.

Because 1 always equals 1, putting that bit in has absolutely no effect whatsoever on how the code or query works. Basically, you're putting it there as a marker.

This way, when the error message showed up and the query was quoted, it would include the marker (the "and x=x" part), and that would show me which query had the bad code before it.

Maybe this was basic or nothing new for a lot of you, but I'm still kind of new at this, and I'm glad I figured it out before I had to carefully examine all the code I would have had to look at, because that would have been a pain in my ass. :) But if this helps even just one of you, it was worth it for me to post this.

Admin 02-25-2002 05:00 AM

Doesn't the MySQL optimizer removes stuff like 1=1 from queries?

JJR512 02-25-2002 07:59 PM

Aparently not, because when I got the error message again, there it was, 4=4. :)

Maybe it SKIPS processing it, but it at least passes it through so it can get into an error message.

Admin 02-26-2002 06:24 AM

No it does remove that from the query, but only when it hits the MySQL server. In explain=1 it shows what PHP gets. :)

JJR512 02-27-2002 12:14 AM

Well, whatever...it doesn't really matter if that part of the query gets executed or not. The important thing is that it shows up in the error message, which is the point. I stuck it there as a marker to show me which of four identical queries was causing a problem. Each had something different, so I could tell which one was the bad one. As long as it shows up in the error message, that's all that's important. And it does show up.

drazq 03-12-2002 08:06 AM

Hmm,

if I have a problem with a mysql query I always do an echo of the query on the line before I run it.

If I can't figgure out what the problem is then (if the query seems right) I copy and paste it into phpMyAdmin and run it there.

If it works there, then something else is wrong :)

- draz Q.

JJR512 03-12-2002 05:27 PM

Those are good tips, but you need to know first which query is giving you problems before you can put an echo before it, or run it in phpMyAdmin. My tip helps you determine which query is the one that's giving you trouble. After you determine that, THEN you can do the stuff that you said.

Zia 04-27-2006 04:06 AM

ummm is there MySqlOptizer for Vb availavble?

kall 04-27-2006 06:12 AM

*sigh*

People found the archive through that post in the 'Archive the vB2 forums?' thread and are now resurrecting long dead threads. Marvellous.

Xorlev 05-08-2006 12:21 AM

Quote:

Originally Posted by Zia
ummm is there MySqlOptizer for Vb availavble?

To beat the dead horse a little more...no. The query optimizer is a part of the MySQL server it's self, and thus any query passed to it is run through the optimizer first. It doesn't matter if it's a query vBulletin executes through PHP, from the mysql tool in SSH, or the C++ interface.

Code Monkey 05-08-2006 02:19 AM

Can vb.org please install the hack that closes old threads. This is an epidemic.


All times are GMT. The time now is 12:29 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01203 seconds
  • Memory Usage 1,730KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (11)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete