MariaDB [DRAFT]
Created at 2017-04-13T11:32:44+09:00

cli client

```

# Build from source

$ mkdir -p out/_install $ cd out/Default $ cmake -G Ninja ../ -DCMAKE_INSTALL_PREFIX=$PWD/_install $ ninja -j 2 install $ ninja -t browse --port=8989 # it's good to see dependency since it shows separation of components

Running mysql server out of tree

$ cd out/_install

Check configuration

$ ./bin/mysqld --verbose --help

this script runs some sql scripts (e.g. scripts/mysql_system_tables.sql) via mysqld --bootstrap

Q. what's special about --bootstrap ? (does it accept stdin for script to run ?)

$ ./scripts/mysql_install_db --datadir=$PWD/data

Run server with minimal option

--no-defaults: not read default .cnf files

--datadir: put storage data out of tree

$ ./bin/mysqld --no-defaults --datadir=$PWD/data 2017-05-26 12:09:52 140629066374912 [Note] ./bin/mysqld (mysqld 10.2.7-MariaDB) starting as process 8966 ... 2017-05-26 12:09:52 140629066374912 [Warning] Changed limits: max_open_files: 1024 max_connections: 151 table_cache: 431 2017-05-26 12:09:52 140629066374912 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2017-05-26 12:09:52 140629066374912 [Note] InnoDB: Uses event mutexes 2017-05-26 12:09:52 140629066374912 [Note] InnoDB: Compressed tables use zlib 1.2.11 2017-05-26 12:09:52 140629066374912 [Note] InnoDB: Using Linux native AIO 2017-05-26 12:09:52 140629066374912 [Note] InnoDB: Number of pools: 1 2017-05-26 12:09:52 140629066374912 [Note] InnoDB: Using SSE2 crc32 instructions 2017-05-26 12:09:52 140629066374912 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M 2017-05-26 12:09:52 140629066374912 [Note] InnoDB: Completed initialization of buffer pool 2017-05-26 12:09:52 140628526679808 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority(). 2017-05-26 12:09:52 140629066374912 [Note] InnoDB: Highest supported file format is Barracuda. 2017-05-26 12:09:52 140629066374912 [Note] InnoDB: 128 out of 128 rollback segments are active. 2017-05-26 12:09:52 140629066374912 [Note] InnoDB: Creating shared tablespace for temporary tables 2017-05-26 12:09:52 140629066374912 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ... 2017-05-26 12:09:52 140629066374912 [Note] InnoDB: File './ibtmp1' size is now 12 MB. 2017-05-26 12:09:52 140629066374912 [Note] InnoDB: 5.7.18 started; log sequence number 1620154 2017-05-26 12:09:52 140628100904704 [Note] InnoDB: Loading buffer pool(s) from /home/hiogawa/code/others/MariaDBserver/out/_install/data/ib_buffer_pool 2017-05-26 12:09:52 140628100904704 [Note] InnoDB: Buffer pool(s) load completed at 170526 12:09:52 2017-05-26 12:09:53 140629066374912 [Note] Plugin 'FEEDBACK' is disabled. 2017-05-26 12:09:53 140629066374912 [Note] Server socket created on IP: '::'. 2017-05-26 12:09:53 140629066374912 [Note] Reading of all Master_info entries succeded 2017-05-26 12:09:53 140629066374912 [Note] Added new Master_info '' to hash table 2017-05-26 12:09:53 140629066374912 [Note] ./bin/mysqld: ready for connections.

Run client from another shell

$ ./bin/mysql -u root

CREATE DATABASE db1; CREATE TABLE db1.t1 (id INT, num INT); INSERT INTO db1.t1 (id, num) VALUES (0, 123); SELECT * FROM db1.t1; MariaDB [(none)]> select * from db1.t1; +------+------+ | id | num | +------+------+ | 0 | 123 | +------+------+ 1 row in set (0.00 sec) UPDATE db1.t1 SET num = 456 WHERE id = 0; SELECT * FROM db1.t1; +------+------+ | id | num | +------+------+ | 0 | 456 | +------+------+ 1 row in set (0.00 sec) DELETE FROM db1.t1 WHERE id = 0; SELECT * FROM db1.t1; Empty set (0.00 sec)

# Follow basic flow

- database creation
- table creation
- row insert/update/delete


# Configuration

$ out/_install/bin/mysqld --no-defaults --verbose --help # list available options

# TODO

- system table
  - mysql, information_schema, performance_schema
- server (tcp)
- master-slave  
- sql implementation
- data structure/layout in storage and in memory
- transaciton
- replication (wsrep)
- plugin architecture
- authentication and priviledge system
- client library (tcp)
- client locking and dead lock detection
- data format on disk and on memory
  - innodb and Barracuda ?
- application level client
  - connection pooling (e.g. db client wrapper in rails)
- locking/concurrency
  - example: https://bugs.mysql.com/bug.php?id=48652
  - single row (S (shared) or X (exclusive))
  - multiple rows (IS (intention shared) or IX (intention exclusive))
  - index record ()
  - 'no key update' lock in postgres
    - http://paquier.xyz/postgresql-2/postgres-9-3-feature-highlight-for-key-share-and-for-no-key-update/

[table A]

id fid a0 b0 <- insert a1 b0 <- insert

--

[table B]

id val
b0, x <- update b1, y <- update


transaction [T1]

begin
insert a0 <1> (S lock on b0) update b0 <3> (X lock on b0, blocked by S lock of <2>) end

transaction [T2]

begin
insert a1 <2> (S lock on b0) update b0 <4> (X lock on b0, blocked by S lock of <1>) end

where server sees request in the order of <1>, <2>, <3>, and <4>. ```

Reference