如果要分成5个表
存数据的时候 用 % id 值为1、2、3、4、5分别进入不同的表那么查询的时候改怎么查呢?比如一些要group by 或 order by  ,这些操作的时候,该如何结合起来这些表呢?

解决方案 »

  1.   

    详细说明,主要操作是什么,查询?
    如果上查询,什么条件,经常用的SQL语句是什么?
      

  2.   


    比如排序 
    select * from order order_xxx  by gmt_create limit 1000 , 30 ;那么这里的 order_xxx  该怎么写呢?
      

  3.   


    比如排序 
    select * from order order_xxx  by gmt_create limit 1000 , 30 ;那么这里的 order_xxx  该怎么写呢?比如五张表  order_01 order_02 order_03 order_04 order_05 ,分别根据order_id % 5 的值来存储不同的数据。那么我现在要这五张表合并执行下面这个查询
    select * from order order_xxx  by gmt_create limit 1000 , 30 ;
    改怎么做呢?
      

  4.   

    可以使用MYSQL的merge 存储引擎。
    13.8. The MERGE Storage Engine
    The MERGE storage engine, also known as the MRG_MyISAM engine, is a collection of identical MyISAM tables that can be used as one. “Identical” means that all tables have identical column and index information. You cannot merge MyISAM tables in which the columns are listed in a different order, do not have exactly the same columns, or have the indexes in different order. However, any or all of the MyISAM tables can be compressed with myisampack. See Section 4.6.5, “myisampack — Generate Compressed, Read-Only MyISAM Tables


    The following example shows how to create a MERGE table: mysql> CREATE TABLE t1 (
        ->    a INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
        ->    message CHAR(20)) ENGINE=MyISAM;
    mysql> CREATE TABLE t2 (
        ->    a INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
        ->    message CHAR(20)) ENGINE=MyISAM;
    mysql> INSERT INTO t1 (message) VALUES ('Testing'),('table'),('t1');
    mysql> INSERT INTO t2 (message) VALUES ('Testing'),('table'),('t2');
    mysql> CREATE TABLE total (
        ->    a INT NOT NULL AUTO_INCREMENT,
        ->    message CHAR(20), INDEX(a))
        ->    ENGINE=MERGE UNION=(t1,t2) INSERT_METHOD=LAST;Note that the a column is indexed as a PRIMARY KEY in the underlying MyISAM tables, but not in the MERGE table. There it is indexed but not as a PRIMARY KEY because a MERGE table cannot enforce uniqueness over the set of underlying tables. 
      

  5.   


    当前使用的是InnoDB , 把数据切换到merge , 操作方便吗?  
      

  6.   

    那还是直接做个视图算了。create view xxxx as 
    select * from t1
    union all
    select * from t2
    unoin all
    select * from t3;
      

  7.   

    如果是这样,不用分表,在gmt_create 上建立索引
      

  8.   

    一般Mysql单表数据量达到多少之后就要考虑分表了呢?
      

  9.   


    不管多少数据,先考虑 分区。
    我使用下面的命令,得到如下结果mysql> show variables like '%partition%' ;
    Empty set (0.00 sec)是不是说我现在的mysql没有支持分区的引擎 ,如果要支持分区 ,该怎么操作呢?