MySQL

                   mysql-casual#1 (2010-12-10)
                            @xaicron




2010   12   13
• @xaicron (               )

                 • works at DeNA
                 • blog http://blog.livedoor.jp/xaicron/


2010   12   13
Perl




2010   12   13
JPerl Advent Calender



2010   12   13
2010   12   13
http://perl-users.jp/articles/advent-calendar/help.html




2010   12   13
2010   12   13
MySQL



2010   12   13
2010   12   13
2010   12   13
2010   12   13
2010   12   13
myfinder




2010   12   13
2010   12   13
cv.



2010   12   13
Agenda


                 • Sharding
                 • Partitioning


2010   12   13
Sharding

2010   12   13
Sharding


                 • Shared Nothing
                 •        DB




2010   12   13
user_id


2010   12   13
2010   12   13
Sharding



2010   12   13
DB




2010   12   13
•
                 • Disk   IO

                 •


2010   12   13
Sharding



2010   12   13
•   JOIN


                 •
                 •
                 •          orz



2010   12   13
2010   12   13
user_id        auto_increment


                           DB




2010   12   13
DB




2010   12   13
2010   12   13
•
                 •
                 •
                 •

2010   12   13
Partitioning

2010   12   13
Partitioning
                 •

                 •               SELECT
                         Partition        drop

                 • 5.1       --with-partition



2010   12   13
2010   12   13
2010   12   13
Partitioning



2010   12   13
•

                 •          Partition


                 • Partition            SELECT

                 • SUM() COUNT()

                 •

2010   12   13
2010   12   13
ALTER TABLE
                    table_name
                 DROP PARTITIONS!!


2010   12   13
Partition




2010   12   13
2010   12   13
2010   12   13
SELECT
                 Partition




2010   12   13
CREATE TABLE `tweet` (
          `id` bigint(20) NOT NULL,
          `tweet` varchar(140) NOT NULL,
          `created_on` timestamp NOT NULL,
          PRIMARY KEY (`id`)
       ) ENGINE=InnoDB DEFAULT CHARSET=utf8
       PARTITION BY RANGE ( UNIX_TIMESTAMP(created_on) ) (
          PARTITION p20101210 VALUE LESS THAN (1291906800),
          PARTITION p20101211 VALUE LESS THAN (1291993200),
          PARTITION p20101212 VALUE LESS THAN (1292079600),
          PARTITION p20101213 VALUE LESS THAN (1292166000),
          PARTITION p20101214 VALUE LESS THAN (1292252400)



2010   12   13
20101210




2010   12   13
SELECT * FROM tweet WHERE created_on >
                    ‘20101210’ AND tweet = ‘mysqlcasual’;




2010   12   13
p20101210
                     partition




2010   12   13
EXPLAIN PARTITION SELECT ...
                         partition




2010   12   13
Partitioning



2010   12   13
• PARTITION
                   created_on)
                                      KEY (
                                      Primary Key

                 • UNIQ
                 •                          SELECT


                 • UNIX_TIMESTAMP()
                   v5.1.43
                                 !!


2010   12   13
2010   12   13
•
                 •       MySQL

                 •               (
                                     cron
                     )

                 •                    !!



2010   12   13
cv.



2010   12   13
Sharding   Partitioning




2010   12   13
2010   12   13
2010   12   13
2010   12   13
2010   12   13

MySQL データ分割入門