views:

59

answers:

1

I have a table with over 4 million rows, I want to split this table in more tables, i.e one table with 50k rows. I also need to perform a search on these tables, whats the best way to do it? with JOIN, or? do you have some better ideas?

Best Regards,

QUERY

            $do = $this->select()
              ->where('branche LIKE ?',''.mysql_escape_string($branche).'%')
              ->order('premium DESC');  

Zend_Paginator

        $d = $firmen->doSearch($finalType,$theKeyword,$thePLZ,$theBranche,false,false,false,$theOrder);

    $paginator = new Zend_Paginator(

    new Zend_Paginator_Adapter_DbSelect($d)
    );      

    if ($d !== false) {
        //$paginator = Zend_Paginator::factory($d);
        $paginator->setItemCountPerPage(5)
                  ->setPageRange(10)
                  ->setCurrentPageNumber($pag);

        $this->view->data = $paginator;
A: 

Why do you want to split them? Performance issues?

Phliplip
Yea it takes about 12 sec to do a query with everything optimized, metadata cache and everything...
Uffo
A query on just that table? No joins?
Inkspeak
Yeah...it's only one table at the moment, and one query, thats why I want to split it..and do some joins, but I said..to ask first, mabe you guys have some better ideas than join :D
Uffo
@Uffo, it seems a little strange that it's taking that long on a single table. Unless you're doing some funky left joins back to the same table, using DISTINCT(), or LIKE '%SOMETHING' I'd be curious about your schema. Are there any indexes on that table?
Inkspeak
Yes I have indexes on the table, but It's a table with 4 million rows, is actually normal to take that long...I want to split it, and create tables..like 1 table with 50000 rows...and when I do the search to join all the tables..i guess it will be faster..
Uffo
Can you post your query that takes 12 seconds?
Phliplip
I second the request for the query. I don't think 12 seconds is all that "normal" unless you're doing something to ignore the indexes. If you're doing a "search" then it's possible a better indexing service will give you better results and allow you to leave your table intact. But, I'd like to see the query, if possible.
Inkspeak
Remember to use 'LIMIT 1' if you are requesting a single row ie. 'WHERE id = XXX'If not the query will continue to search the entire table.
Phliplip
@Inkspeak updated, check the main post!
Uffo
Your LIKE query should be taking advantage of indexing. Could you post the end query? like this <?php die($do); ?>
Phliplip
@Uffo: Gotcha. Have you debugged through to see the actual SQL query? I ask because that will prove whether or not the Paginator is passing along the proper limits. Also, does your Db_Table class have any relational properties like $_dependentTables? I'm also assuming your index is on the 'branche` column? Is that a fulltext index?Just more questions for your question.
Inkspeak
@Inkspeak, @Phliplip: Queries with the LIKE statement do NOT use indexes when the % wildcard is at the start, that's why it takes so long. See http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html
nuqqsa
@nuqqsa: Yep, i know! His query is with % is at the end.. thus it should use indexes
Phliplip