Myanmar Unicode Sorting in MySQL (MariaDB)

MySQL မှာ Sorting စီတာကို သံလွင် Soft က Keith (1976-2011) မဆုံး ခင် ကတည်းက ဖန်တီးထားခဲ့ပါတယ်။ Keith ဆုံးပြီး နောက်ပိုင်း သူ့ သူငယ်ချင်း တစ်ယောက်က သူ့ code တွေ အကုန်လုံးကို github မှာ တင်ထားတဲ့ အတွက် mysql Myanmar Collation source code ကို ရယူနိုင်သလို ကိုငွေထွန်းက 2006 မှာ MySQL ရဲ့ bug report site မှာ Myanmar Collation Extension ထည့်ဖို့ ပြောထားတာကို တွေ့နိုင်ပါတယ်။ သို့ပေမယ့် MySQL အနေနဲ့ offical support လုပ်ဖို့ အစီအစဉ် မရှိသေးဘူးဆိုတဲ့ အဖြေနဲ့ ရပ်ဆိုင်းခဲ့ရပါတယ်။

MySQL Is Owned By Oracle

MySQL ကို ဇန်နဝါရီ ၂၀၀၈ မှာ Sun Microsystems က ဝယ်ခဲ့ပါတယ်။ ဧပြီ ၂၀၀၉ မှာတော့ Oracle က Sun Microsystems ကို ဝယ်ခဲ့ပါတယ်။ ဒါကြောင့် MySQL ဟာ Oracle ရဲ့ ပိုင်ဆိုင်မှု ဖြစ်သွားပါတယ်။ Oracle ဟာလည်း Oracle DB ရှိတာကြောင့် နောင်တချိန်မှာ MySQL က ရပ်တည်မှုဟာ မသေချာသလို opensource မဟုတ်တော့တာလည်း ဖြစ်နိုင်တာကြောင့် MariaDB ဆိုပြီး MySQL ကို Fork လုပ်ပြီး ခွဲထွက်လာပါတယ်။

MariaDB , Fork From MySQL

MariaDB ဟာ community developed fork ဖြစ်တာကြောင့် MySQL မှာ bug fix မလုပ်သေးတာတွေကို အမြန်ဆုံး bug fix လုပ်ပေးပါတယ်။ နောက်ပြီးတော့ InnoDB storage engine replace အတွက် XtraDB ထည့်သွင်းသလို Aria storage engine ကိုလည်း ထပ်ဖြည့်ထားပါတယ်။ Aira ဟာ MySQL future verison မှာ ပါလာမယ့် sroage engine ပါ။

Lead Developer ကတော့ Michael Widenius , founder of MySQL ပါပဲ။ သူ့ company MySQL AB ကို Sun ကို $1 billion နဲ့ ရောင်းချခဲ့တာပါ။ သူ့ သမီးနာမည် က My ဖြစ်တဲ့ အတွက် database နာမည်ကို MySQL လို့ ပေးခဲ့သလို နောက်ထပ် သမီး တစ်ယောက်နာမည်ကတော့ Maria ပါ။ ဒါကြောင့် MySQL ကနေ fork လုပ်ထားတဲ့ DB က MariaDB ဆိုပြီး သူနာမည်ပေးခဲ့ပါတယ်။ ဒါကြောင့် MariaDB ဟာ MySQL လိုမျိုး စိတ်ချ ယုံကြည်ရပြီးတော့ လက်ရှိ MySQL databaes က data တွေ programming code (driver) တွေ နဲ့ အဆင်ပြေပြေ အလုပ်လုပ်နိုင်ပါတယ်။ ဘာမှ ပြောင်းလဲစရာ မလိုပါဘူး။

MariaDB with Myanmar Collation

MariaDB ဟာ ၈ လပိုင်း ၂၀၁၃ မှာ Myanmar collation ကို စတင် support လုပ်ဖို့ ကြိုးစားခဲ့ပါတယ်။ ဘာကြောင့်လည်းဆိုတော့ ၂၀၀၆ လောက်က ကို ငွေထွန်း တင်ထားတဲ့ request ကို mysql က မဖြေရှင်းထားသေးလို့ပါ။ ကို စည်သူသွင် က ကူညီ စစ်ဆေးခဲ့တာကို တွေ့ရပါတယ်။ MariaDB version 10.0 (27 Dec 2013 release) ကနေ စပြီးတော့ Myanmar Collaction ကို support လုပ်ပါတယ်။

MariaDB သွင်းပြီးရင်တော့ command line ကနေ

SHOW COLLATION LIKE '%myanmar%';

ဆိုပြီး ရိုက်လိုက်ရင် myanmar collaction ကို တွေ့ရပါမယ်။

myanmar

တကယ်လို့ table တည်ဆောက်မယ်ဆိုရင်တော့

CREATE TABLE IF NOT EXISTS `SampleTable` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `myanmar_text` text CHARACTER SET utf8 COLLATE utf8_myanmar_ci NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_myanmar_ci;

SampleTable မှာ myanmar_text ဆိုတဲ့ field ကို utf8_myanmar_ci ကို အသုံးပြုထားပါတယ်။ နောက်ပြီး table ကိုလည်း utf8_myanamr_ci ကို အသုံးပြုထားပါတယ်။

တကယ်လို့ ရှိပြီးသား table ကို ပြောင်းချင်ရင်တော့

ALTER TABLE  `SampleTable` DEFAULT CHARACTER SET utf8 COLLATE utf8_myanmar_ci

table ကို မဟုတ်ပဲ field တစ်ခုတည်းကို ပြောင်းချင်ရင်တော့

ALTER TABLE  `SampleTable` CHANGE  `myanmar_text`  `myanmar_text` TEXT CHARACTER SET utf8 COLLATE utf8_myanmar_ci

ကျွန်တော်တို့ Field ကို utf8_myanmar_ci သတ်မှတ်ပြီးသွားရင်တော့ မြန်မာလို sorting စီလို့ရပါပြီ။

ဥပမာ အနေနဲ့ ကျွန်တော် အောက်က SQL နဲ့ insert လုပ်လိုက်ပါမယ်။

INSERT INTO  `myanmar`.`SampleTable` (`myanmar_text`) VALUES ('အ');
INSERT INTO  `myanmar`.`SampleTable` (`myanmar_text`) VALUES ('အု');
INSERT INTO  `myanmar`.`SampleTable` (`myanmar_text`) VALUES ('အို');
INSERT INTO  `myanmar`.`SampleTable` (`myanmar_text`) VALUES ('အော');
INSERT INTO  `myanmar`.`SampleTable` (`myanmar_text`) VALUES ('အံ');
INSERT INTO  `myanmar`.`SampleTable` (`myanmar_text`) VALUES ('အေ');

ပြီးရင် ကျွန်တော်တို့တွေ query နဲ့ ထည့်ထားတွေကို စစ်ကြည့်ပါမယ်။

select

data တွေက ဝင်သွားပါပြီ။ ORDER BY နဲ့ စီကြည့်ရအောင်။

order

Sorting အမှန် နဲ့ ထွက်လာတာကို တွေ့ရပါလိမ့်မယ်။

Not Supporting Emoji

MariaDB မှာ utf8mb4_myanmar_ciက emoji support လုပ်ဖို့အတွက်ပါ။

Why Sorting

ဘာကြောင့် ကျွန်တော်တို့ Database မှာ sorting လိုအပ်သလဲ ဆိုရင်တော့ သုံးစရာ နေရာ အများကြီးပါ။ ဥပမာ။။ လူနာမည်တွေကို က ကနေ အ အထိ စီတဲ့ အခါ။ ဒါမှမဟုတ် website တွေမှာ search result က sorting စီပြီး ပြတဲ့ အခါမှာ အသုံးပြုနိုင်ပါတယ်။ online shopping website တွေ မှာ ပစ္စည်း ရှာပြီး ပစ္စည်း စာရင်းကို နာမည် အလိုက် ငယ်စဉ် ကြီးလိုက် စီတာ ၊ ကြီးစဉ်ငယ်လိုက် စီတာတွေကို MariaDB အသုံးပြုပြီး လွယ်လင့်တကူ ဖြေရှင်းနိုင်ပါလိမ့်မယ်။ သို့ပေမယ့် Unicode ကို သုံးစွဲဖို့ လိုအပ်ပါတယ်။

3 Comments

  1. San Lin Naing says:

    ကျေးဇူး အရမ်းတင်ပါတယ်ခင်ဗျာ။ ကိုစေတန်ဆီကနေ ဗဟုသုတတွေ အများကြီး ရပါတယ်။

  2. 123 says:

    Thank sir

  3. zwe says:

    Thank you so much ^-^

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.