English 中文(简体)
动态选择多栏索引的最佳方法
原标题:Best way to index on multiple column for dynamic select

基本上,我有一个大约7亿多行的桌子,并不断更新每天约200千-300克的浏览量,每个月末,我将冲淡3个多月的数据。

CREATE TABLE TESTRECORD (
  TIMEADDED timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  SERIAL varchar(8) NOT NULL,
  ENDTIME varchar(14) NOT NULL,
  MODEL varchar(2) NOT NULL,
  PROCESS int(4) NOT NULL,
  PF varchar(4) NOT NULL,
  COMID varchar(6) NOT NULL,
  COMTP varchar(3) NOT NULL,
  TRIAL varchar(4) NOT NULL,
  TEST varchar(8) NOT NULL,
  SECTION int(2) NOT NULL,
  DATA_0 float NOT NULL,
  DATA_1 float NOT NULL,
  DATA_2 float NOT NULL,
  DATA_3 float NOT NULL,
  DATA_4 float NOT NULL,
  DATA_5 float NOT NULL,
  PRIMARY KEY (SN,ENDTIME,SECTION),
  UNIQUE KEY BASESN (SN,ENDTIME,MODEL,PROCESS,PF,COMID,TRIAL,TEST,SECTION),
  KEY COMID (COMID),
  KEY TRIAL (TRIAL),
  KEY PF (PF),
  KEY TEST (TEST)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

The unique key defined the parameters that will be used in the select statement. Since the basic function for this table is for dynamic data analyzing, so there is no specific orders what will occurs in the where clause and how many of them will be used, and there could be some random group by by one or two of the cols from the unique key as well. So it is pretty much impossible to index all the possible combo to ensure fast operation on any giving select.

我的理解是,根据在图象中列明的顺序,我的舱面使用指数,就我而言,如果我在选择发言中使用SN、ENDTIME和PF,那么,只有头2列将使用独特的钥匙。 是否有有效的方法可以将指数按每栏或单项技术细分为1个指数,以加速比值或至少实现条款中不同栏目的总体平等业绩?

thank!

最佳回答

MySQL的指数像你在书末可能发现的指数。 如果你看着一本“Ppepperoni pizza”的书,你首先看着普佩罗尼,然后看皮扎。 如果你只找“pizza”,那么这一指数对你没有任何帮助,因为Pizza在指数中是第二位到Pepperoni,如果你首先看一看Pepperoni,就只能找到Pizza。 这就是X栏Y的指数如何运行。 如果你计划按该顺序处理关于第十和Y组的询问,那么这两个栏的索引就是合理的。 如果你想就X和Y问题提出询问,那么复合指数就没有达到多少目的!

我建议你坐下来,确定你最经常处理哪些问题,并分析你的储存和处理能力。 指数可以占用大量空间,特别是在数百万人中工作。 指数是储存空间与处理权之间的典型权衡,不熟悉你的数据库的人都无法告诉你什么是你特定情况的最佳指数或组合。

另见每个栏中储存的独特价值数目。 MySQL与Oracle不同,不支持标准表格的模拟索引(使用B-Tree)。 除技术细节外,这意味着,按相对较少的独特价值计算,在一栏上建立一个指数,使每个指数空间单位的数值与你认为的一样高。

一份最后说明是,对于某些类型的数据分析,你可能希望考虑将某些数据出口到一个中东和北非表。 气象组织表格基本上是临时表格,在用户会议中保存其结构。 他们失去数据,但在你使用这些数据或发生坠毁时,他们的结构不是。 记忆表支持 HLM指数,该指数显示指数栏的数值,以加速数据检索。 在大多数情况下,它们都非常快,如果正确使用,可以大大改善业绩。

如果你真心希望行选,我会建议你看看一看“高级业绩报告”。

问题回答

我想建议您考虑不同的储存,例如一栏储存发动机,如Infobright的公开源分析数据库。 它是建立在神秘结构基础上的,完全喜欢与我方合作,只是针对大数据和分析性询问。 www.infobright.org

任何表格的解决办法:

SELECT 
  CONCAT(
     ALTER TABLE  , 
    TABLE_NAME, 
       , 
     ADD  , 
    IF(
      NON_UNIQUE = 1, 
      CASE UPPER(INDEX_TYPE) WHEN  FULLTEXT  THEN  FULLTEXT INDEX  WHEN  SPATIAL  THEN  SPATIAL INDEX  ELSE CONCAT(
         INDEX  , INDEX_NAME,   USING  , INDEX_TYPE
      ) END, 
      IF(
        UPPER(INDEX_NAME) =  PRIMARY , 
        CONCAT(
           PRIMARY KEY USING  , INDEX_TYPE
        ), 
        CONCAT(
           UNIQUE INDEX  , INDEX_NAME,   USING  , 
          INDEX_TYPE
        )
      )
    ), 
     ( , 
    GROUP_CONCAT(
      DISTINCT CONCAT(  , COLUMN_NAME,   ) 
      ORDER BY 
        SEQ_IN_INDEX ASC SEPARATOR  ,  
    ), 
     ); 
  ) AS  Show_Add_Indexes  
FROM 
  information_schema.STATISTICS 
WHERE 
  TABLE_SCHEMA =  your_database  
  and TABLE_NAME =  your_table ;
-- GROUP BY 
--   TABLE_NAME, 
--   INDEX_NAME 
-- ORDER BY 
--   TABLE_NAME ASC, 
--   INDEX_NAME ASC;




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签