I'm working in a project in Drupal6 and we are removing all the curly brackets from the table names in the queries because we don't need table prefixes and supposedly this will improve performance.

Is this reasoning correct or curly brackets should be used even if we don't need table prefixing?

  • 1
    In case you haven't already, I'd recommend profiling the site to understand where the bottleneck is. It's very easy to spend time optimising the wrong bits, and having zero or negligible impact on the actual time it takes to do things!
    – Andy
    Commented Apr 30, 2012 at 14:54

1 Answer 1


You should always keep the curly brackets in there, if only for maintainability and portability of your system. What if the next release of Drupal requires those curly brackets? I'm not saying it will, but if a framework gives you guidelines it does so for a reason; you should probably follow them.

As for the performance benefit, I think you'll find it's negligible at best. db_query() runs this statement regardless of whether your string contains curly brackets or not in the first instance:

$query = db_prefix_tables($query);

So db_prefix_tables() will get run on the string regardless of whether or not your table names actually need prefixing or not.

I'd advise stepping through db_prefix_tables() and using that to decide whether or not you should remove the brackets for performance reasons; you'll probably be making your decision based on the performance of the lower-level strtr() function, which does all the string replacement work.

There's a condition in that function that depends on a global variable not being empty to continue...if you want to 'turn off' the database table prefixing (and limit any inherent performance losses), ensuring that the global variable ($db_prefix) is empty when you run your query would probably do the trick (though that might make your data susceptible to race conditions; it depends on your setup).

Make sure you don't turn $db_prefix off for the entire site permanently though, or you'll have to go through all core and contributed modules and remove the curly brackets from their queries too!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.