[TYPO3-dev] Questions about exec_PREPAREquery

Mathias Schreiber [wmdb] mathias.schreiber at wmdb.de
Tue Jun 7 09:13:37 CEST 2011


Am 06.06.11 20:55, schrieb Stefan Frömken:
> I'm wondering that TYPO3-Statements are faster than the old way
> allthough TYPO3-Statements are using the same functions like the old
> way. And it has to load an additional class.
>
> I don't understand this?!?! Why is it faster?

Let me take you into the insides of a database.
You say "give me row 14 of table pages".
MySQL will then parse that query and check it for errors.
After that it will be recoded into binary data (if using a remote host) 
and sent to the DB server.

Now imagine a typical TYPO3 scenario with hundreds of queries that look 
almost the same.
MySQL will parse the query once (!), check it for syntax errors once (!) 
and recode it to binary once (!).

Additionally there was some talk about query-caching prep-statements as 
well, but I never really checked if it became part of the mySQL code.

On the other hand, there is one downside (like always in life :)):
Say you have a remote DB host that is either very far away from your 
webserver or under heavy load or whatever slows the machine down.
Using prep-statements always include 2 messages to the server rather 
than one.
If you have long trip times (> 40ms) to your mysql host, prep-statements 
might work out worse than normal statements.

THis is why I did not opt for "prep-statements all throughout the TYPO3 
core" because under certain consitions it makes things worse :/
Unfourtunately, in 99% of all use-cases, they are better in every respect.

Hope this clears things up a bit.
cheers
Mathias

-- 
Ernesto, Nov. 9th 2010:
"In the graphics generation routines of TYPO3 *anything* could cause a
side effect."




More information about the TYPO3-dev mailing list