Àí½âMySQL¡ª¡ª²¢ÐÐÊý¾Ý¿âÓë·ÖÇø(Partition)
ÔÎÄ£º http://www.cnblogs.com/hustcat/archive/2009/12/24/1631674.html
1¡¢²¢ÐÐÊý¾Ý¿â
1.1¡¢²¢ÐÐÊý¾Ý¿âµÄÌåϵ½á¹¹
²¢ÐлúµÄ³öÏÖ£¬´ßÉúÁ˲¢ÐÐÊý¾Ý¿âµÄ³öÏÖ£¬²»¶Ô£¬Ó¦¸ÃÊǹØϵÔËËã±¾À´¾ÍÊǸ߶ȿɲ¢Ðеġ£¶ÔÊý¾Ý¿âϵͳÐÔÄܵĶÈÁ¿Ö÷ÒªÓÐÁ½ÖÖ·½Ê½£º(1)ÍÌÍÂÁ¿(Throughput)£¬ÔÚ¸ø¶¨µÄʱ¼ä¶ÎÀïËùÄÜÍê³ÉµÄÈÎÎñÊýÁ¿£»(2)ÏìӦʱ¼ä(Response time)£¬µ¥¸öÈÎÎñ´ÓÌá½»µ½Íê³ÉËùÐèÒªµÄʱ¼ä¡£¶ÔÓÚ´¦Àí´óÁ¿Ð¡ÊÂÎñµÄϵͳ£¬Í¨¹ý²¢Ðеش¦ÀíÐí¶àÊÂÎñ¿ÉÒÔÌá¸ßËüµÄÍÌÍÂÁ¿¡£¶ÔÓÚ´¦Àí´óÊÂÎñµÄϵͳ£¬Í¨¹ý²¢ÐеÄÖ´ÐÐÊÂÎñµÄ×ÓÈÎÎñ£¬¿ÉÒÔËõ¶ÌϵͳÉÎӦʱ¼ä¡£
²¢ÐлúÓÐÈýÖÖ»ù±¾µÄÌåϵ½á¹¹£¬ÏàÓ¦µÄ£¬²¢ÐÐÊý¾Ý¿âµÄÌåϵ½á¹¹Ò²¿ÉÒÔ´ó¸Å·ÖΪÈýÀࣺ
¹²ÏíÄÚ´æ(share memeory)£ºËùÓд¦ÀíÆ÷¹²ÏíÒ»¸ö¹«¹²µÄ´æ´¢Æ÷£»
¹²Ïí´ÅÅÌ(share disk)£ºËùÓд¦ÀíÆ÷¹²Ïí¹«¹²µÄ´ÅÅÌ£»ÕâÖֽṹÓÐʱÓÖ½Ð×ö¼¯Èº(cluster)£»
ÎÞ¹²Ïí(share nothing)£ºËùÓд¦ÀíÆ÷¼È²»¹²ÏíÄڴ棬Ҳ²»¹²Ïí´ÅÅÌ¡£
ÈçͼËùʾ£º
1.1.1¡¢ ¹²ÏíÄÚ´æ
¸Ã½á¹¹°üÀ¨¶à¸ö´¦ÀíÆ÷¡¢Ò»¸öÈ«¾Ö¹²ÏíµÄÄڴ棨Ö÷´æ´¢Æ÷£©ºÍ¶à¸ö´ÅÅÌ´æ´¢£¬¸÷¸ö´¦ÀíÆ÷ͨ¹ý¸ßËÙͨѶÍøÂ磨Interconnection Network£©Óë¹²ÏíÄÚ´æÁ¬½Ó£¬²¢¾ù¿ÉÖ±½Ó·ÃÎÊϵͳÖеÄÒ»¸ö¡¢¶à¸ö»òÈ«²¿µÄ´ÅÅÌ´æ´¢£¬ÔÚϵͳÖУ¬ËùÓеÄÄÚ´æºÍ´ÅÅÌ´æ´¢¾ùÓɶà¸ö´¦ÀíÆ÷¹²Ïí¡£
ÕâÖֽṹµÄÓŵãÔÚÓÚ£¬´¦ÀíÆ÷Ö®¼äµÄͨÐÅЧÂʼ«¸ß£¬·ÃÎÊÄÚ´æµÄËÙ¶ÈÒª±ÈÏûϢͨÐÅ»úÖÆÒª¿ìºÜ¶à¡£ÕâÖֽṹµÄȱµãÔÚÓÚ£¬´¦ÀíÆ÷µÄ¹æÄ£²»Äܳ¬¹ý32¸ö»òÕß64¸ö£¬ÒòΪ×ÜÏß»ò»¥±ßÍøÂçÊÇÓÉËùÓеĴ¦ÀíÆ÷¹²Ïí£¬Ëü»á±ä³ÉÆ¿¾±¡£µ±´¦ÀíÆ÷ÊýÁ¿µ½´ïijһ¸öµãʱ£¬ÔÙÔö¼Ó´¦ÀíÆ÷ÒѾûÓÐʲôºÃ´¦¡£
¹²ÏíÄÚ´æ½á¹¹Í¨³£ÔÚÿ¸ö´¦ÀíÆ÷ÉÏÓкܴóµÄ¸ßËÙ»º´æ£¬´Ó¶ø¼õÉÙ¶ÔÄÚ´æµÄ·ÃÎÊ¡£µ«ÊÇ£¬ÕâЩ¸ßËÙ»º´æ±ØÐë±£³ÖÒ»Ö£¬Ò²¾ÍÊÇ»º´æÒ»ÖÂÐÔ(cache-coherency)µÄÎÊÌâ¡£
1.1.2¡¢ ¹²Ïí´ÅÅÌ
¸Ã½á¹¹Óɶà¸ö¾ßÓжÀÁ¢Äڴ棨Ö÷´æ´¢Æ÷£©µÄ´¦ÀíÆ÷ºÍ¶à¸ö´ÅÅÌ´æ´¢¹¹³É£¬¸÷¸ö´¦ÀíÆ÷Ï໥֮¼äûÓÐÈκÎÖ±½ÓµÄÐÅÏ¢ºÍÊý¾ÝµÄ½»»»£¬¶à¸ö´¦ÀíÆ÷ºÍ´ÅÅÌ´æ´¢ÓɸßËÙͨÐÅÍøÂçÁ¬½Ó£¬Ã¿¸ö´¦ÀíÆ÷¶¼¿ÉÒÔ¶Áдȫ²¿µÄ´ÅÅÌ´æ´¢¡£
¹²Ïí´ÅÅÌÓë¹²ÏíÄÚ´æ½á¹¹Ïà±È£¬ÓÐÒÔÏÂһЩÓŵ㣺(1)ÿ¸ö´¦ÀíÆ÷¶¼ÓÐ×Ô¼ºµÄ´æ´¢Æ÷£¬´æ´¢×ÜÏß²»ÔÙÊÇÆ¿¾±£»(2)ÒÔÒ»ÖֽϾ¼ÃµÄ·½Ê½ÌṩÁËÈÝ´íÐÔ(fault tolerence)£¬Èç¹ûÒ»¸ö´¦Æ÷·¢Éú¹ÊÕÏ£¬ÆäËü´¦ÀíÆ÷¿ÉÒÔ´úÌ湤×÷¡£
¸Ã½á¹¹µÄÖ÷ÒªÎÊÌâ²»ÊÇÔÚÓÚ¿ÉÀ©Õ¹ÐÔÎÊÌ⣬ËäÈ»´æ´¢×ÜÏß²»ÊÇÆ¿¾±£¬µ«ÊÇ£¬Óë´ÅÅÌÖ®¼äµÄÁ¬½ÓÓÖ³ÉÁËÆ¿¾±¡£
ÔËÐÐRdbµÄDEC¼¯ÈºÊǹ²Ïí´ÅÅ̵ÄÌåϵ½á¹¹µÄÔçÆÚÉÌÓû¯²úÆ·Ö®Ò»(DECºóÀ´±»Compaq¹«Ë¾ÊÕ¹º£¬ÔÙºóÀ´£¬OracleÓÖ´ÓCompaqÊÖÖÐÈ¡µÃRdb£¬·¢Õ¹³ÉÏÖÔÚµÄOracle RAC)¡£
1.1.3¡¢ ÎÞ¹²Ïí
¸Ã½á¹¹Óɶà¸öÍêÈ«¶ÀÁ¢µÄ´¦Àí½Úµã¹¹³É£¬Ã¿¸ö´¦Àí½Úµã¾ßÓÐ×Ô¼º¶ÀÁ¢µÄ´¦ÀíÆ÷¡¢¶ÀÁ¢µÄÄڴ棨Ö÷´æ´¢Æ÷£©ºÍ¶ÀÁ¢µÄ´ÅÅÌ´æ´¢£¬¶à¸ö´¦Àí½ÚµãÔÚ´¦ÀíÆ÷¼¶ÓɸßËÙͨÐÅÍøÂçÁ¬½Ó£¬ÏµÍ³Öеĸ÷¸ö´¦ÀíÆ÷ʹÓÃ×Ô¼ºµÄÄÚ´æ¶ÀÁ¢µØ´¦Àí×Ô¼ºµÄÊý¾Ý¡£
Õâ ÖֽṹÖУ¬Ã¿Ò»¸ö´¦Àí½Úµã¾ÍÊÇÒ»¸öСÐ͵ÄÊý¾Ý¿âϵͳ£¬¶à¸ö½ÚµãÒ»Æð¹¹³ÉÕû¸öµÄ·Ö²¼Ê½µÄ²¢ÐÐÊý¾Ý¿âϵͳ¡£ÓÉÓÚÿ¸ö´¦ÀíÆ÷ʹÓÃ×Ô¼ºµÄ×ÊÔ´´¦Àí×Ô¼ºµÄÊý¾Ý£¬²»´æ ÔÚÄÚ´æºÍ´ÅÅ̵ÄÕùÓã¬Ìá¸ßµÄÕûÌåÐÔÄÜ¡£ÁíÍâÕâÖֽṹ¾ßÓÐÓÅÁ¼µÄ¿ÉÀ©Õ¹ÐÔ¡ª¡ªÖ»ÐèÔö¼Ó¶îÍâµÄ´¦Àí½Úµã£¬¾Í¿ÉÒÔÒÔ½Ó½üÏßÐԵıÈÀýÔö¼ÓϵͳµÄ´¦ÀíÄÜÁ¦¡£
ÕâÖֽṹÖУ¬ÓÉÓÚÊý¾ÝÊǸ÷¸ö´¦ÀíÆ÷˽Óеģ¬Òò´ËϵͳÖÐÊý¾ÝµÄ·Ö²¼¾ÍÐèÒªÌØÊâµÄ´¦Àí£¬ÒÔ¾¡Á¿±£Ö¤ÏµÍ³Öи÷¸ö½ÚµãµÄ¸ºÔØ»ù±¾Æ½ºâ£¬µ«ÔÚÄ¿Ç°µÄÊý¾Ý¿âÁìÓò£¬Õâ¸öÊý¾Ý·Ö²¼ÎÊÌâÒѾÓбȽϺÏÀíµÄ½â¾ö·½°¸¡£
ÓÉÓÚÊý¾ÝÊÇ·Ö²¼ÔÚ¸÷¸ö´¦Àí½ÚµãÉϵģ¬Òò´Ë£¬Ê¹ÓÃÕâÖֽṹµÄ²¢ÐÐÊý¾Ý¿âϵͳ£¬ÔÚÀ©Õ¹Ê±²»¿É±ÜÃâµØ»áµ¼ÖÂÊý¾ÝÔÚÕû¸öϵͳ·¶Î§ÄÚµÄÖØ·Ö²¼£¨Re-Distribution£©ÎÊÌâ¡£
Shared-Nothing½á¹¹µÄµäÐÍ´ú±íÊÇTeradata(²¢ÐÐÊý¾Ý¿âµÄÏÈÇý)£¬ÖµµÃÒ»ÌáµÄÊÇ£¬MySQL NDB ClusterҲʹÓÃÁËÕâÖֽṹ¡£
1.2¡¢I/O²¢ÐÐ(I/O Parallelism)
I/O²¢ÐеÄ×î¼òµ¥ÐÎʽÊÇͨ¹ý¶Ô¹Øϵ»®·Ö£¬·ÅÖõ½¶à¸ö´ÅÅÌÉÏÀ´Ëõ¼õ´Ó´ÅÅ̶ÁÈ¡¹ØϵµÄʱ¼ä¡£²¢ÐÐÊý¾Ý¿âÖÐÊý¾Ý»®·Ö×îͨÓõÄÐÎʽÊÇˮƽ»®·Ö(horizontal portioning)£¬Ò»¸ö¹ØϵÖеÄÔª×é±»»®·Öµ½¶à¸ö´ÅÅÌ¡£
1.2.1¡¢³£Óû®·Ö¼¼Êõ
¼Ù¶¨½«Êý¾Ý»®·Öµ½n¸ö´ÅÅÌD0£¬D1£¬¡£¬DnÖС£
(1) ÂÖת·¨(round-bin)¡£¶Ô¹Øϵ˳ÐòɨÃ裬½«µÚi¸öÔª×é´æ´¢µ½±êºÅΪDi%nµÄ´ÅÅÌÉÏ£»¸Ã·½Ê½±£Ö¤ÁËÔª×éÔÚ¶à¸ö´ÅÅÌÉϾùÔÈ·Ö²¼¡£
(2) É¢Áл®·Ö(hash partion)¡£Ñ¡¶¨Ò»¸öÖµÓòΪ{0, 1, ¡,n-1}µÄÉ¢Áк¯Êý£¬¶Ô¹ØϵÖеÄÔª×é»ùÓÚ»®·ÖÊôÐÔ½øÐÐÉ¢ÁС£Èç¹ûÉ¢Áк¯Êý·µ»Øi£¬Ôò½«Æä´æ´¢µ½µÚi¸ö´ÅÅÌ¡£
(3) ·¶Î§»®·Ö(range partion)¡£
ÓÉÓÚ½«¹Øϵ´æ´¢µ½¶à¸ö´ÅÅÌ£¬¶ÁдʱÄÜͬʱ½øÐУ¬»®·Ö(partion)ÄÜ´ó´óÌá¸ßϵͳµÄ¶ÁдÐÔÄÜ¡£Êý¾ÝµÄ´æÈ¡¿ÉÒÔ·ÖΪÒÔϼ¸Àࣺ
(1) ɨÃèÕû¸ö¹Øϵ£»
(2) µã²éѯ(point query)£¬Èçname = ¡°hustcat¡±£»
(3) ·¶Î§²éѯ(range query)£¬Èç 20 < age < 30¡£
²»Í¬µÄ»®·Ö¼¼Êõ£¬¶ÔÕâЩ´æÈ¡ÀàÐ͵ÄЧÂÊÊDz»Í¬µÄ£º
ÂÖת·¨ÊʺÏ˳ÐòɨÃè¹Øϵ£¬¶Ôµã²éѯºÍ·¶Î§²éѯµÄ´¦Àí½Ï¸´ÔÓ¡£
É¢Áл®·ÖÌرðÊʺϵã²éѯ£¬ËÙ¶È×î¿ì¡£
·¶Î§»®·Ö¶Ôµã²éѯ¡¢·¶Î§²éѯÒÔ¼°Ë³ÐòɨÃ趼֧³Ö½ÏºÃ£¬ËùÒÔÊÊÓÃÐԺܹ㡣µ«ÊÇ£¬ÕâÖÖ·½Ê½´æÔÚÒ»¸öÎÊÌ⡪¡ªÖ´ÐÐƫб(execution skew)£¬Ò²¾ÍÊÇ˵ijЩ·¶Î§µÄÔª×é½Ï¶à£¬Ê¹µÃ´óÁ¿µÄI/O³öÏÖÔÚij¼¸¸ö´ÅÅÌ¡£
1.3¡¢²éѯ¼ä²¢ÐÐ(interquery parallism)
²éѯ¼ä²¢ÐÐÖ¸µÄÊDz»Í¬µÄ²éѯ»òÊÂÎñ¼ä²¢ÐеÄÖ´ÐС£ÕâÖÖÐÎʽµÄ²¢ÐпÉÒÔÌá¸ßÊÂÎñµÄÍÌÍÂÁ¿£¬È»¶ø£¬µ¥¸öÊÂÎñ²¢²»ÄÜÖ´Ðеøü¿ì(¼´ÏìӦʱ¼ä²»ÄܼõÉÙ)¡£²éѯ¼äµÄ²¢ÐÐÖ÷ÒªÓÃÓÚÀ©Õ¹ÊÂÎñ´¦Àíϵͳ£¬ÔÚµ¥Î»Ê±¼äÄÚÄܹ»´¦Àí¸ü¶àµÄÊÂÎñ¡£
²éѯ¼ä²¢ÐÐÊÇÊý¾Ý¿âϵͳ×îÒ×ʵÏÖµÄÒ»ÖÖ²¢ÐУ¬ÔÚ¹²ÏíÄÚ´æµÄ²¢ÐÐϵͳ(ÈçSMP)ÖÐÓÈÆäÕâÑù¡£Îªµ¥´¦ÀíÆ÷Éè¼ÆµÄÊý¾Ý¿âϵͳ¿ÉÒÔ²»ÓÃÐ޸ģ¬»òÕߺÜÉÙÐ޸ľÍÄÜÓõ½¹²ÏíÄÚ´æµÄÌåϵ½á¹¹¡£
ÔÚ¹²Ïí´ÅÅ̺ÍÎÞ¹²ÏíµÄÌåϵ½á¹¹ÖУ¬ÊµÏÖ²éѯ¼ä²¢ÐÐÒª¸ü¸´ÔÓһЩ¡£¸÷¸ö´¦ÀíÐèҪе÷À´½øÐзâËø¡¢ÈÕÖ¾²Ù×÷µÈµÈ£¬Õâ¾ÍÐèÒª´¦ÀíÆ÷Ö®¼äµÄ´«µÝÏûÏ¢¡£²¢ÐÐÊý¾Ý¿âϵͳ±ØÐë±£Ö¤Á½¸ö´¦ÀíÆ÷²»»áͬʱ¸üÐÂͬһÊý¾Ý¡£¶øÇÒ£¬´¦ÀíÆ÷·ÃÎÊÊý¾Ýʱ£¬ÏµÍ³±ØÐë±£Ö¤´¦ÀíÆ÷»º´æµÄÊý¾ÝÊÇ×îеÄÊý¾Ý£¬¼´»º´æÒ»ÖÂÐÔÎÊÌâ¡£
1.4¡¢²éѯÄÚ²¢ÐÐ(intraquery parallism)
²éѯÄÚ²¢ÐÐÊÇÖ¸µ¥¸ö²éѯҪÔÚ¶à¸ö´¦ÀíÆ÷ºÍ´ÅÅÌÉÏͬʱ½øÐС£ÎªÁËÀí½â£¬À´¿¼ÂÇÒ»¸ö¶Ôij¹Øϵ½øÐÐÅÅÐòµÄ²éѯ¡£¼ÙÉè¹ØϵÒѾ»ùÓÚij¸öÊôÐÔ½øÐÐÁË·¶Î§»®·Ö£¬´æ´¢ÓÚ¶à¸ö´ÅÅÌÉÏ£¬²¢ÇÒ»®·ÖÊÇ»ùÓÚ»®·ÖÊôÐԵġ£ÔòÅÅÐò²Ù×÷¿ÉÒÔÈçϽøÐУº¶Ôÿ¸ö·ÖÇø²¢ÐеÄÅÅÐò£¬È»ºó½«¸÷¸öÒѾÓÐÐòµÄ·ÖÇøºÏ²¢µ½Ò»Æð¡£
µ¥¸ö²éѯµÄÖ´ÐпÉÒÔÓÐÁ½ÖÖ²¢Ðз½Ê½£º
(1) ²Ù×÷ÄÚ²¢ÐÐ(Intraoperation parallism)£ºÍ¨¹ý²¢ÐеÄÖ´ÐÐÿһ¸öÔËË㣬ÈçÅÅÐò¡¢Ñ¡Ôñ¡¢Á¬½ÓµÈ£¬À´¼Ó¿ìÒ»¸ö²éѯµÄ´¦ÀíËٶȡ£
(2) ²Ù×÷¼ä²¢ÐÐ(Interoperation parallism)£ºÍ¨¹ý²¢ÐеÄÖ´ÐÐÒ»¸ö²éѯÖеĶà¸ö²»Í¬µÄÔËË㣬À´¼ÓËÙ¶ÈÒ»¸ö²éѯµÄ´¦ÀíËٶȡ£
×¢ÒâÁ½Õß¼äµÄÇø±ð£¬Ç°Õß¿ÉÒÔÈÏΪ¶à¸ö´¦ÀíÆ÷ͬʱִÐÐÒ»¸öÔËË㣬¶øºóÕßÊǶà¸ö´¦ÀíÆ÷ͬʱִÐв»Í¬µÄÔËËã¡£
ÕâÁ½ÖÖÐÎʽ֮¼äµÄ²¢ÐÐÊÇ»¥Ïಹ³äµÄ£¬²¢ÇÒ¿ÉÒÔͬʱ´æÔÚÓÚÒ»¸ö²éѯÖС£Í¨³£ÓÉÓÚÒ»¸ö²éѯÖеÄÔËËãÊýÄ¿Ïà¶ÔÓÚÔª×éÊýÄ¿ÊǽÏСµÄ£¬ËùÒÔµ±²¢ÐжÈÔö¼Óʱ£¬µÚÒ»ÖÖ·½Ê½È¡µÃµÄЧ¹û¸üÏÔÖø¡£
2¡¢MySQLµÄ·ÖÇø(partion)
2.1¡¢MySQL·ÖÇø¸ÅÊö
ÔÚMySQLÖУ¬InnoDB´æ´¢ÒýÇ泤ÆÚÖ§³Ö±í¿Õ¼äµÄ¸ÅÄ²¢ÇÒMySQL·þÎñÆ÷ÉõÖÁÔÚ·ÖÇøÒýÈë֮ǰ£¬¾ÍÄÜÅäÖÃΪ´æ´¢²»Í¬µÄÊý¾Ý¿âʹÓò»Í¬µÄÎïÀí·¾¶¡£·ÖÇø(partion)¸ü½øÒ»²½£¬ËüÔÊÐíÄãͨ¹ýÉèÖø÷ÖÖ¹æÔò½«Ò»¸ö±íµÄ¸÷¸ö·ÖÇø¿çÎļþϵͳ´æ´¢¡£Êµ¼ÊÉÏ£¬²»Í¬Î»ÖõIJ»Í¬±í·ÖÇøÊÇ×÷Ϊһ¸öµ¥¶ÀµÄ±íÀ´´æ´¢µÄ¡£Óû§ËùÑ¡ÔñµÄ¡¢ÊµÏÖÊý¾Ý·Ö¸îµÄ¹æÔò±»³ÆΪ·ÖÇøº¯Êý(partioning function)£¬ÕâÔÚMySQLÖÐËü¿ÉÒÔÊÇÄ£Êý£¬»òÕßÊǼòµ¥µÄÆ¥ÅäÒ»¸öÁ¬ÐøµÄÊýÖµÇø¼ä»òÊýÖµÁÐ±í£¬»òÕßÊÇÒ»¸öÄÚ²¿HASHº¯Êý£¬»òÒ»¸öÏßÐÔHASHº¯Êý¡£
×î³£¼ûÊǵÄˮƽ·ÖÇø(horizontal partitioning)£¬Ò²¾ÍÊǽ«±íµÄ²»Í¬µÄÔª×é·ÖÅäµ½²»Í¬µÄÎïÀí·ÖÇøÉÏ¡£Ä¿Ç°£¬MySQL 5.1»¹²»Ö§³Ö´¹Ö±·ÖÇø(vertical partitioning)£¬¼´½«±íµÄ²»Í¬ÁзÖÅäµ½²»Í¬µÄÎïÀí·ÖÇø¡£Äã¿ÉÒÔʹÓÃMySQLÖ§³ÖµÄ´ó¶àÊý´æ´¢ÒýÇæÀ´´´½¨±íµÄ·ÖÇø£¬ÔÚMySQL 5.1ÖУ¬Í¬Ò»¸ö±íµÄ¸÷¸ö·ÖÇø±ØÐëʹÓÃÏàͬµÄ´æ´¢ÒýÇ棬±ÈÈ磬Äã²»ÄܶÔÒ»¸ö·ÖÇøʹÓÃMyISAM£¬¶ø¶ÔÁíÒ»¸ö·ÖÇøʹÓÃInnoDB¡£µ«ÊÇ£¬Äã¿ÉÒÔ¶Ôͬһ¸öÊý¾Ý¿âµÄ²»Í¬µÄ±íʹÓò»Í¬µÄ´æ´¢ÒýÇæ¡£
ҪΪij¸ö·ÖÇø±íÅäÖÃÒ»¸öרÃŵĴ洢ÒýÇ棬±ØÐëÇÒÖ»ÄÜʹÓÃ[STORAGE] ENGINE Ñ¡ÏÕâÈçͬΪ·Ç·ÖÇø±íÅäÖô洢ÒýÇæÒ»Ñù¡£µ«ÊÇ£¬±ØÐë¼Çס[STORAGE] ENGINE£¨ºÍÆäËûµÄ±íÑ¡Ï±ØÐëÁÐÔÚÓÃÔÚCREATE TABLEÓï¾äÖеÄÆäËûÈκηÖÇøÑ¡Ïî֮ǰ¡£ÏÂÃæµÄÀý×Ó¸ø³öÁËÔõÑù´´½¨Ò»¸öͨ¹ýHASH·Ö³É6¸ö·ÖÇø¡¢Ê¹ÓÃInnoDB´æ´¢ÒýÇæµÄ±í£º
CREATE TABLE ti (id INT, amount DECIMAL(7,2), tr_date DATE) ENGINE=INNODB PARTITION BY HASH( MONTH(tr_date) ) PARTITIONS 6; |
×¢£º·ÖÇø±ØÐë¶ÔÒ»¸ö±íµÄËùÓÐÊý¾ÝºÍË÷Òý£»²»ÄÜÖ»¶ÔÊý¾Ý·ÖÇø¶ø²»¶ÔË÷Òý·ÖÇø£¬·´Ö®ÒàÈ»£¬Í¬Ê±Ò²²»ÄÜÖ»¶Ô±íµÄÒ»²¿·Ö½øÐзÖÇø¡£
·ÖÇø¶ÔÊý¾Ý¿â¹ÜÀíϵͳʵÏÖ²¢Ðд¦ÀíÓÐ×ÅÖØÒªµÄÓ°Ï죬Èç¹û¶ÔÊý¾Ý½øÐзÖÇø£¬ÔòºÜÈÝÒ×½øÐв¢Ðд¦Àí£¬µ«ÊÇ£¬MySQL»¹Ã»Óгä·ÖÀûÓ÷ÖÇøµÄÕâÖÖ²¢ÐÐÓÅÊÆ£¬¶øÕâÒ²ÊÇËü¸Ä½øµÄ·½Ïò (ÕâÖÖ·ÖÖÎ˼ÏëÉîÉîµÄÓ°Ïì×Ų¢ÐмÆË㣬¶øÇÒÔÚ²¢ÐмÆËã·½Ãæ¾ßÓÐÌìÈ»ÓÅÊÆ)¡£MySQLµÄ·ÖÇø£¬»á¸øϵͳ´øÀ´ÒÔÏÂһЩÓŵ㣺
Óëµ¥¸ö´ÅÅÌ»òÎļþϵͳ·ÖÇøÏà±È£¬µ¥¸ö±í¿ÉÒÔ´æ´¢¸ü¶àµÄÊý¾Ý¡£
¶ÔÓÚÄÇЩÒѾʧȥ±£´æÒâÒåµÄÊý¾Ý£¬Í¨³£¿ÉÒÔͨ¹ýɾ³ýÓëÄÇЩÊý¾ÝÓйصķÖÇø£¬ºÜÈÝÒ×µØɾ³ýÄÇЩÊý¾Ý¡£Ïà·´µØ£¬ÔÚijЩÇé¿öÏ£¬Ìí¼ÓÐÂÊý¾ÝµÄ¹ý³ÌÓÖ¿ÉÒÔͨ¹ýΪÄÇЩÐÂÊý¾ÝרÃÅÔö¼ÓÒ»¸öеķÖÇø£¬À´ºÜ·½±ãµØʵÏÖ¡£
¶ÔÓÚ´øWhereµÄÌõ¼þ²éѯÓï¾ä£¬¿ÉÒԵõ½¸ü´óµÄÓÅ»¯£»Ö»ÐèÒª²éѯijЩ·ÖÇø£¬¶ø²»ÓÃɨÃèÈ«²¿·ÖÇø¡£
»¹ÓÐÆäËüһЩÓŵ㣬²»¹ýMySQL 5.1»¹²»Ö§³Ö£º
һЩ¾ÛºÏº¯Êý£¬±ÈÈçSUM() ºÍCOUNT()£¬Äܹ»ºÜÈÝÒ׵IJ¢ÐÐÖ´ÐУ»
ͨ¹ý²¢ÐÐI/O£¬¿ÉÒÔ´ó´óÌá¸ß²éѯµÄÍÌÍÂÁ¿¡£
×¢£ºÊµ¼ÊÉÏ£¬·ÖÇø²»ÂÛÊǶÔI/O²¢ÐУ¬»¹ÊDzéѯÄÚ²¢ÐУ¬¶¼ÓÐ×ÅÖØÒªµÄÓ°Ïì¡£Ö»²»¹ýMySQLÔÚÕâ·½Ãæ×öµÃ»¹²»¹»¶à(²»¹ý£¬ÕýÔڸĽø)£¬¶øOracle¶ÔÓÚ²éѯÄÚ²¢ÐУ¬×öÁ˺ܶ๤×÷¡£
2.2¡¢·ÖÇøÀàÐÍ
MySQL 5.1ÖпÉÓõķÖÇøÀàÐÍ°üÀ¨£º
RANGE·ÖÇø(portioning)£º¸ù¾ÝÁÐÖµËùÊôµÄ·¶Î§Çø¼ä£¬½«Ôª×é·ÖÅäµ½¸÷¸ö·ÖÇø¡£
LIST·ÖÇø£ºÀàËÆÓÚ°´RANGE·ÖÇø£¬Çø±ðÔÚÓÚLIST·ÖÇøÊÇ»ùÓÚÁÐֵƥÅäÒ»¸öÀëÉ¢Öµ¼¯ºÏÖеÄij¸öÖµÀ´½øÐÐÑ¡Ôñ¡£
HASH·ÖÇø£º¸ù¾ÝÓû§¶¨ÒåµÄº¯ÊýµÄ·µ»ØÖµÀ´½øÐÐÑ¡ÔñµÄ·ÖÇø£¬¸Ã±í´ïʽʹÓý«Òª²åÈëµ½±íÖеÄÕâЩÐеÄÁÐÖµ½øÐмÆËã¡£Õâ¸öº¯Êý¿ÉÒÔ°üº¬MySQL ÖÐÓÐЧµÄ¡¢²úÉú·Ç¸ºÕûÊýÖµµÄÈκαí´ïʽ¡£
KEY·ÖÇø£ºÀàËÆÓÚ°´HASH·ÖÇø£¬Çø±ðÔÚÓÚKEY·ÖÇøÖ»Ö§³Ö¼ÆËãÒ»Áлò¶àÁУ¬ÇÒMySQL ·þÎñÆ÷ÌṩÆä×ÔÉíµÄ¹þÏ£º¯Êý¡£
2.2.1¡¢·¶Î§·ÖÇø
·¶Î§·ÖÇøÊÇͨ¹ý¼ÆËã±í´ïʽµÄÖµËùÊôµÄ·¶Î§Çø¼ä£¬¶ÔÔª×é½øÐзÖÇø¡£ÕâЩÇø¼äÒªÇóÁ¬ÐøÇÒ²»ÄÜÏ໥Öصþ£¬Ê¹ÓÃVALUES LESS THAN²Ù×÷·ûÀ´½øÐж¨Òå¡£ÔÚÏÂÃæµÄ¼¸¸öÀý×ÓÖУ¬¼Ù¶¨Äã´´½¨ÁËÒ»¸öÈçϵÄÒ»¸ö±í£¬¸Ã±í±£´æÓÐ20¼ÒÒôÏñµêµÄÖ°Ô±¼Ç¼£¬Õâ20¼ÒÒôÏñµêµÄ±àºÅ´Ó1µ½20¡£
CREATE TABLE employees ( id INT NOT NULL, fname VARCHAR(30), lname VARCHAR(30), hired DATE NOT NULL DEFAULT '1970-01-01', separated DATE NOT NULL DEFAULT '9999-12-31', job_code INT NOT NULL, store_id INT NOT NULL ); |
Äã¿ÉÒÔ¸ù¾ÝÐèÒª¶Ô¸Ã±í½øÐи÷ÖÖ·ÖÇø£¬±ÈÈ磬Äã¿ÉÒÔͨ¹ýstore_idÀ´½øÐзÖÇø£º
CREATE TABLE employees ( id INT NOT NULL, fname VARCHAR(30), lname VARCHAR(30), hired DATE NOT NULL DEFAULT '1970-01-01', separated DATE NOT NULL DEFAULT '9999-12-31', job_code INT NOT NULL, store_id INT NOT NULL ) PARTITION BY RANGE (store_id) ( PARTITION p0 VALUES LESS THAN (6), PARTITION p1 VALUES LESS THAN (11), PARTITION p2 VALUES LESS THAN (16), PARTITION p3 VALUES LESS THAN (21) ); |
ºÜÈÝÒ×È·¶¨Êý¾Ý(72, 'Michael', 'Widenius', '1998-06-25', NULL, 13)±»²åÈë·ÖÇøp2£»µ«ÊÇ£¬Èç¹ûÒ»ÌõÊý¾ÝµÄstore_id = 21£¬»áÔõôÑùÄØ£¿ÓÉÓÚûÓйæÔò´¦Àí´óÓÚ20µÄÇé¿ö£¬ËùÒÔ·þÎñÆ÷»á±¨´í¡£Äã¿ÉÒÔͨ¹ýÈçÏ·½Ê½À´´¦ÀíÕâÖÖÇé¿ö£º
CREATE TABLE employees ( id INT NOT NULL, fname VARCHAR(30), lname VARCHAR(30), hired DATE NOT NULL DEFAULT '1970-01-01', separated DATE NOT NULL DEFAULT '9999-12-31', job_code INT NOT NULL, store_id INT NOT NULL ) PARTITION BY RANGE (store_id) ( PARTITION p0 VALUES LESS THAN (6), PARTITION p1 VALUES LESS THAN (11), PARTITION p2 VALUES LESS THAN (16), PARTITION p3 VALUES LESS THAN MAXVALUE ); |
MAXVALUE ±íʾ×î´óµÄ¿ÉÄܵÄÕûÊýÖµ¡£ÏÖÔÚ£¬store_id ÁÐÖµ´óÓÚ»òµÈÓÚ16£¨¶¨ÒåÁ˵Ä×î¸ßÖµ£©µÄËùÓÐÐж¼½«±£´æÔÚ·ÖÇøp3ÖС£ÔÚ½«À´µÄij¸öʱºò£¬µ±É̵êÊýÒѾÔö³¤µ½25, 30, »ò¸ü¶à £¬¿ÉÒÔʹÓÃALTER TABLEÓï¾äΪÉ̵ê21-25, 26-30,µÈµÈÔö¼ÓеķÖÇø
RANGE·ÖÇøÔÚÈçϳ¡ºÏÌرðÓÐÓãº
(1) µ±ÐèҪɾ³ý¡°¾ÉµÄ¡±Êý¾Ýʱ¡£ ÔÚÉÏÃæµÄÀý×ÓÖУ¬ÄãÖ»Ðè¼òµ¥µØʹÓà ¡°ALTER TABLE employees DROP PARTITION p0£»¡±À´É¾³ýËùÓÐÔÚ1991ÄêÇ°¾ÍÒѾֹͣ¹¤×÷µÄ¹ÍÔ±Ïà¶ÔÓ¦µÄËùÓÐÐС£¶ÔÓÚÓдóÁ¿ÐÐµÄ±í£¬Õâ±ÈÔËÐÐÒ»¸öÈç¡°DELETE FROM employees WHERE YEAR(separated) <= 1990£»¡±ÕâÑùµÄÒ»¸öDELETE²éѯҪÓÐЧµÃ¶à¡£
(2) ¾³£ÒÀÀµÓÚ·ÖÇøÊôÐÔ½øÐвéѯ¡£ÀýÈ磬µ±Ö´ÐÐÒ»¸öÈç¡°SELECT COUNT(*) FROM employees WHERE YEAR(separated) = 2000 GROUP BY store_id£»¡±ÕâÑùµÄ²éѯʱ£¬MySQL¿ÉÒÔºÜѸËÙµØÈ·¶¨Ö»ÓзÖÇøp2ÐèҪɨÃ裬ÕâÊÇÒòΪÓàϵķÖÇø²»¿ÉÄÜ°üº¬ÓзûºÏ¸ÃWHERE×Ó¾äµÄÈκμǼ¡£×¢£ºÕâÖÖÓÅ»¯»¹Ã»ÓÐÔÚMySQL 5.1Ô´³ÌÐòÖÐÆôÓ㬵«ÊÇ£¬Óйع¤×÷ÕýÔÚ½øÐÐÖС£
·¶Î§·ÖÇøµÄȱµã¾ÍÊÇÈÝÒ׳öÏÖÖ´ÐÐƫб£¬Õâ»áÓ°ÏìϵͳÐÔÄÜ¡£
2.2.2¡¢HASH·ÖÇø
HASH·ÖÇøÖ÷ÒªÓÃÀ´È·±£Êý¾ÝÔÚÔ¤ÏÈÈ·¶¨ÊýÄ¿µÄ·ÖÇøÖÐƽ¾ù·Ö²¼¡£ÔÚRANGEºÍLIST·ÖÇøÖУ¬±ØÐëÃ÷È·Ö¸¶¨Ò»¸ö¸ø¶¨µÄÁÐÖµ»òÁÐÖµ¼¯ºÏÓ¦¸Ã±£´æÔÚÄĸö·ÖÇøÖУ»¶øÔÚHASH·ÖÇøÖУ¬MySQL ×Ô¶¯Íê³ÉÕâЩ¹¤×÷£¬ÄãËùÒª×öµÄÖ»ÊÇ»ùÓÚ½«Òª±»¹þÏ£µÄÁÐÖµÖ¸¶¨Ò»¸öÁÐÖµ»ò±í´ïʽ£¬ÒÔ¼°Ö¸¶¨±»·ÖÇøµÄ±í½«Òª±»·Ö¸î³ÉµÄ·ÖÇøÊýÁ¿¡£
Äã¿ÉÒÔͨ¹ýÒªÔÚCREATE TABLE Óï¾äÉÏÌí¼ÓÒ»¸ö¡°PARTITION BY HASH (expr)¡±×Ӿ䣬ÆäÖС°expr¡±ÊÇÒ»¸ö·µ»ØÒ»¸öÕûÊýµÄ±í´ïʽ¡£Ëü¿ÉÒÔ½ö½öÊÇ×Ö¶ÎÀàÐÍΪMySQL ÕûÐ͵ÄÒ»ÁеÄÃû×Ö¡£´ËÍ⣬ÄãºÜ¿ÉÄÜÐèÒªÔÚºóÃæÔÙÌí¼ÓÒ»¸ö¡°PARTITIONS num¡±×Ӿ䣬ÆäÖÐnum ÊÇÒ»¸ö·Ç¸ºµÄÕûÊý£¬Ëü±íʾ±í½«Òª±»·Ö¸î³É·ÖÇøµÄÊýÁ¿¡£±ÈÈ磺
CREATE TABLE employees ( id INT NOT NULL, fname VARCHAR(30), lname VARCHAR(30), hired DATE NOT NULL DEFAULT '1970-01-01', separated DATE NOT NULL DEFAULT '9999-12-31', job_code INT, store_id INT ) PARTITION BY HASH(store_id) PARTITIONS 4; |
Èç¹ûûÓÐPARTITIONSÓï¾ä£¬Ä¬ÈÏ·ÖÇøÊýΪ1¡£µ«ÊÇ£¬PARTITIONSºóÃæûÓÐÊý×Ö£¬ÏµÍ³»á±¨´í¡£
Ïà¶ÔÓÚ·¶Î§·ÖÇø£¬HASH·ÖÇø¸ü¿ÉÄܱ£Ö¤Êý¾Ý¾ùºâ·Ö²¼¡£
2.2.3¡¢×Ó·ÖÇø(Subpartitioning)
×Ó·ÖÇø£¬Ò²½Ð×ö¸´ºÏ·ÖÇø(composite partitioning)£¬ÊǶԷÖÇø±íµÄÿ¸ö·ÖÇøµÄ½øÒ»²½·Ö¸î¡£ÀýÈ磬
CREATE TABLE ts (id INT, purchased DATE) PARTITION BY RANGE( YEAR(purchased) ) SUBPARTITION BY HASH( TO_DAYS(purchased) ) SUBPARTITIONS 2 ( PARTITION p0 VALUES LESS THAN (1990), PARTITION p1 VALUES LESS THAN (2000), PARTITION p2 VALUES LESS THAN MAXVALUE ); |
±íts ÓÐ3¸öRANGE·ÖÇø¡£Õâ3¸ö·ÖÇøÖеÄÿһ¸ö·ÖÇø¡ª¡ªp0, p1, ºÍ p2 ¡ª¡ªÓÖ±»½øÒ»²½·Ö³ÉÁË2¸ö×Ó·ÖÇø¡£Êµ¼ÊÉÏ£¬Õû¸ö±í±»·Ö³ÉÁË3 * 2 = 6¸ö·ÖÇø¡£µ«ÊÇ£¬ÓÉÓÚPARTITION BY RANGE×Ó¾äµÄ×÷Óã¬ÕâЩ·ÖÇøµÄÍ·2¸öÖ»±£´æ¡°purchased¡±ÁÐÖÐֵСÓÚ1990µÄÄÇЩ¼Ç¼¡£
ÔÚMySQL 5.1ÖУ¬¶ÔÓÚÒѾͨ¹ýRANGE»òLIST·ÖÇøÁ˵ıíÔÙ½øÐзÖÇø¡£×Ó·ÖÇø¼È¿ÉÒÔʹÓÃHASHÏ£·ÖÇø£¬Ò²¿ÉÒÔʹÓÃKEY·ÖÇø¡£
ΪÁ˶Ըö±ðµÄ×Ó·ÖÇøÖ¸¶¨Ñ¡ÏʹÓÃSUBPARTITION ×Ó¾äÀ´Ã÷È·¶¨Òå×Ó·ÖÇøÒ²ÊÇ¿ÉÄܵġ£ÀýÈ磬´´½¨ÔÚÇ°ÃæÀý×ÓÖиø³öµÄͬһ¸ö±íµÄ¡¢Ò»¸ö¸ü¼ÓÏêϸµÄ·½Ê½ÈçÏ£º
CREATE TABLE ts (id INT, purchased DATE) PARTITION BY RANGE( YEAR(purchased) ) SUBPARTITION BY HASH( TO_DAYS(purchased) ) ( PARTITION p0 VALUES LESS THAN (1990) ( SUBPARTITION s0, SUBPARTITION s1 ), PARTITION p1 VALUES LESS THAN (2000) ( SUBPARTITION s2, SUBPARTITION s3 ), PARTITION p2 VALUES LESS THAN MAXVALUE ( SUBPARTITION s4, SUBPARTITION s5 ) ); |
һЩעÒâµã£º
(1) ÿ¸ö·ÖÇøµÄ×Ó·ÖÇøÊý±ØÐëÏàͬ£»
(2) Èç¹ûÔÚÒ»¸ö·ÖÇø±íÉϵÄÈκηÖÇøÉÏʹÓÃSUBPARTITION À´Ã÷È·¶¨ÒåÈκÎ×Ó·ÖÇø£¬ÄÇô¾Í±ØÐ붨ÒåËùÓеÄ×Ó·ÖÇø£»
(3) ÿ¸öSUBPARTITION×Ó¾ä±ØÐë°üº¬Ò»¸ö×Ó·ÖÇøµÄÃû³Æ£»
(4) MySQL 5.1.7¼°Ö®Ç°µÄ°æ±¾£¬Ã¿¸ö·ÖÇøµÄ×Ó·ÖÇøµÄÃû³Æ±ØÐëΨһ£¬µ«ÊÇÔÚÕû¸ö±íÖУ¬Ã»ÓбØҪΨһ¡£´ÓMySQL 5.1.8¿ªÊ¼£¬×Ó·ÖÇøµÄÃû³ÆÔÚÕû¸ö±íÖж¼±ØÐëΨһ¡£
×Ó·ÖÇø¿ÉÒÔÓÃÓÚÌرð´óµÄ±í£¬ÔÚ¶à¸ö´ÅÅ̼ä·ÖÅäÊý¾ÝºÍË÷Òý¡£¼ÙÉèÓÐ6¸ö´ÅÅÌ£¬·Ö±ðΪ/disk0£¬ /disk1£¬ /disk2µÈ£¬¶ÔÓÚÈçÏÂÀý×Ó£º
CREATE TABLE ts (id INT, purchased DATE) PARTITION BY RANGE( YEAR(purchased) ) SUBPARTITION BY HASH( TO_DAYS(purchased) ) ( PARTITION p0 VALUES LESS THAN (1990) ( SUBPARTITION s0 DATA DIRECTORY = '/disk0/data' INDEX DIRECTORY = '/disk0/idx', SUBPARTITION s1 DATA DIRECTORY = '/disk1/data' INDEX DIRECTORY = '/disk1/idx' ), PARTITION p1 VALUES LESS THAN (2000) ( SUBPARTITION s2 DATA DIRECTORY = '/disk2/data' INDEX DIRECTORY = '/disk2/idx', SUBPARTITION s3 DATA DIRECTORY = '/disk3/data' INDEX DIRECTORY = '/disk3/idx' ), PARTITION p2 VALUES LESS THAN MAXVALUE ( SUBPARTITION s4 DATA DIRECTORY = '/disk4/data' INDEX DIRECTORY = '/disk4/idx', SUBPARTITION s5 DATA DIRECTORY = '/disk5/data' INDEX DIRECTORY = '/disk5/idx' ) ); |
3¡¢ÌåÑé·ÖÇø
ÏÂÃæͨ¹ýÀý×ÓÀ´ÌåÑé·ÖÇø£º
(1)´´½¨ÈçÏ·ÖÇø±í£º
CREATE TABLE part_tab ( c1 int default NULL, c2 varchar(30) default NULL, c3 date default NULL ) engine=myisam PARTITION BY RANGE (year(c3)) (PARTITION p0 VALUES LESS THAN (1995), PARTITION p1 VALUES LESS THAN (1996) , PARTITION p2 VALUES LESS THAN (1997) , PARTITION p3 VALUES LESS THAN (1998) , PARTITION p4 VALUES LESS THAN (1999) , PARTITION p5 VALUES LESS THAN (2000) , PARTITION p6 VALUES LESS THAN (2001) , PARTITION p7 VALUES LESS THAN (2002) , PARTITION p8 VALUES LESS THAN (2003) , PARTITION p9 VALUES LESS THAN (2004) , PARTITION p10 VALUES LESS THAN (2010), PARTITION p11 VALUES LESS THAN MAXVALUE ); |
(2)´´½¨Ò»¸ö²»·ÖÇøµÄ±í£º
create table no_part_tab (c1 int(11) default NULL, c2 varchar(30) default NULL, c3 date default NULL ) engine=myisam; |
(1) ´´½¨Ò»¸öÉú³É8000000ÐÐÊý¾ÝµÄ´æ´¢¹ý³Ì£º
delimiter // CREATE PROCEDURE load_part_tab() begin declare v int default 0; while v < 8000000 do insert into part_tab values (v,'testing partitions',adddate('1995-01-01',(rand(v)*36520) mod 3652)); set v = v + 1; end while; end // |
(2) µ÷Óô洢¹ý³Ì£¬Éú³ÉÊý¾Ý£º
mysql> delimiter ; mysql> call load_part_tab(); Query OK, 1 row affected (6 min 35.39 sec) |
(5)
mysql> insert into no_part_tab select * from part_tab; Query OK, 8000000 rows affected (40.98 sec) Records: 8000000 Duplicates: 0 Warnings: 0 |
Êý¾Ý×¼±¸ºÃÁË£¬ÏÂÃ濪ʼ²âÊÔ£º
(6)
mysql> select count(*) from no_part_tab where -> c3 > date '1995-01-01' and c3 < date '1995-12-31'; +----------+ | count(*) | +----------+ | 795181 | +----------+ 1 row in set (4.23 sec)
mysql> select count(*) from part_tab where -> c3 > date '1995-01-01' and c3 < date '1995-12-31'; +----------+ | count(*) | +----------+ | 795181 | +----------+ 1 row in set (0.55 sec) |
ËٶȲîÒìºÜÃ÷ÏÔ£»ÏÂÃ濴һϲéѯ¼Æ»®£º
(8)
mysql> explain select count(*) from no_part_tab where -> c3 > date '1995-01-01' and c3 < date '1995-12-31'\G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: no_part_tab type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 8000000 Extra: Using where 1 row in set (0.00 sec) mysql> explain partitions select count(*) from part_tab where c3 > date '1995-01 -01' and c3 < date '1995-12-31'\G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: part_tab partitions: p1 type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 8000000 #why?? Extra: Using where 1 row in set (0.00 sec)
|
¸½SQLÓï¾ä£º
´úÂëCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> 1 CREATE TABLE part_tab ( c1 int default NULL, c2 varchar(30) default NULL, c3 date default NULL ) engine=myisam PARTITION BY RANGE (year(c3)) ( PARTITION p0 VALUES LESS THAN (1995), PARTITION p1 VALUES LESS THAN (1996) , PARTITION p2 VALUES LESS THAN (1997) , PARTITION p3 VALUES LESS THAN (1998) , PARTITION p4 VALUES LESS THAN (1999), PARTITION p5 VALUES LESS THAN (2000) , PARTITION p6 VALUES LESS THAN (2001) , PARTITION p7 VALUES LESS THAN (2002) , PARTITION p8 VALUES LESS THAN (2003) , PARTITION p9 VALUES LESS THAN (2004) , PARTITION p10 VALUES LESS THAN (2010), PARTITION p11 VALUES LESS THAN MAXVALUE ); create table no_part_tab (c1 int(11) default NULL, c2 varchar(30) default NULL, c3 date default NULL ) engine=myisam; delimiter // CREATE PROCEDURE load_part_tab() begin declare v int default 0; while v < 8000000 do insert into part_tab(c1,c2,c3) values (v,'testing partitions',adddate('1995-01-01',(rand(v)*36520) mod 3652)); set v = v + 1; end while; end // delimiter ; call load_part_tab(); explain select count(*) from no_part_tab where c3 > date '1995-01-01' and c3 < date '1995-12-31'; explain select count(*) from part_tab where c3 > date '1995-01-01' and c3 < date '1995-12-31'; CREATE TABLE part_tab2 ( c1 int default NULL ) engine=myisam PARTITION BY RANGE (c1) ( PARTITION p0 VALUES LESS THAN (5), PARTITION p1 VALUES LESS THAN (10), PARTITION p2 VALUES LESS THAN MAXVALUE ); insert into part_tab2 values(2),(3);
ÍƼöÐÅÏ¢
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
ÆÀÂÛ