Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am testing a very big database (perhaps wp_posts contains hundreds of thousands of rows). As such, the query time, especially the searching query, is extremely long. I'm thinking if there is any other way to split the WP database to multiple tables with different table prefix so that the url structure does not change compared to the original database.

I tried changing $table_prefix in wp_config to wpa_, then i created a sample posts with post name start with a. Then i changed $table_prefix in wp_config to wpb_, then i created a sample posts with post name start with b.

In the next step, i replace the $table_prefix line with

// if query for post start with a, it will go to wpa_ tables,
// if query for post start with b, it will go to wpb_ tables
$prefix = get_the_title(); 

if ($prefix(0) !== 'a') {

    $table_prefix  = 'wpb_';

} else {

    $table_prefix  = 'wpa_';

}

When i tried openning my domain, i got the error Fatal error: Call to undefined function get_the_title() in /home/todaytra/public_html/1/wp-config.php on line 62

I really need to perform this task, usual WPMU installation generates either subdomains or subfolders and it changes the permalink structure of all posts. I tried searching a lot but cannot find any information about this.

share|improve this question
    
Pam, one time or another someone's gonna question your 0% accept rate, so be it now & be it me - if not sure what I'm talking about, please refer to the FAQ :) –  brasofilo Jul 22 '12 at 10:41
    
Well, i don't care about the acceptance rate. I am not an expert in php and wordpress so learning, and it will be much faster and efficient to ask what i don't know rather than spending days searching. In all of the questions i learned something. If you think they are not valid, or my questions are too simple for you, you just delete them. Very simple! After i read someone help here, i appreciate a lot, i also don't think i need to read again in the future. Please delete all of my questions if you want, and don't answer my questions if you are not comfortable –  Pam Apple Jul 23 '12 at 6:31
    
Noooo, please... no offense was intended... the thing is this is a community collaborative site, everything you asked or answered is benefitial to many others now and in the future... *unanswered or without marked correct stay in a kind of limbo and accepting an answer is the way to make the site work better... accepting and upvoting is the way you say thanks to whomever took his/her time and effort to answer... hope we can both help to improve the site, not the opposite... best regards –  brasofilo Jul 23 '12 at 7:46
    
Thanks! After reading good answer or useful suggestion i usually upvote at least once for each question (Accepting answer function does not appear to my account). I almost never ask any question without thinking about it or searching for it for at least some hours, sometime days. Hope you and other people understand about it. –  Pam Apple Jul 23 '12 at 8:01
    
There has to be an accept button for you. If not, get in touch with the support: wordpress.stackexchange.com/help/feedback –  brasofilo Jul 23 '12 at 11:37

1 Answer 1

up vote 4 down vote accepted

Pam,

It sounds like you are facing some major challenges, but I would highly recommend not messing with the table prefix. Doing so will lead to a series of problems, which will require hack after hack to remedy leaving you with a substantial mess of a WordPress installation.

There are some other things you can do to help solve issues with slow queries. While these things are not all necessarily straight forward, they are more worth your time than trying to hack the table prefix.

1) Make sure that you are on WP 3.4+. There were some nice improvements to standard queries in 3.4 that improve query speed.

2) For particularly problematic queries, consider setting no_found_rows to true, update_post_term_cache to false, and update_post_meta_cache to false. These can all lead to improved query performance, but you definitely need to invest some time in understanding the repercussions. Read about them in the Codex: http://codex.wordpress.org/Class_Reference/WP_Query

3) Use a persistent object cache to provide caching of queries. This is definitely a more involved process, but by caching expensive queries to RAM or disk, you can save repeated slow queries.

4) Install a page cache (WP Super Cache does this well) that will help reduce the number of times the expensive query is called. This does not directly address the query issue; however, it reduces the number of times the query may be called.

Beyond the first suggestion, I do not consider any of these to be "easy"; however, what you suggest to do would be a gigantic waste in my opinion and your time would be better spent investigating alternative options to addressing slow queries in WordPress. You will learn more about WordPress, scalability issues, and better ways to do things in a standard WordPress way.

share|improve this answer
    
hi tollmanz, thanks for your very detail explanation. I heard people can use htaccess to run php, so thinking it might be possible to change table prefix by making a php file, when htaccess direct the request it run the php file first. It is complicated any way. i will try all of your suggestion :-) –  Pam Apple Jul 22 '12 at 6:14
1  
I cannot stress it enough, do not hack with table prefix. You will create SO many problems for yourself. I very strongly advise you to put your energy into another method as this hack would not end well. –  tollmanz Jul 22 '12 at 6:20
    
OK, tollmanz, i won't think about hacking the table prefix :-). Thanks! –  Pam Apple Jul 23 '12 at 7:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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