The files are
• sakila-data.sql: The INSERT statements needed to populate the tables as well as the trigger definitions.
• sakila-schema.sql: The schema definition statements.
• sakila.mwb: The MySQL Workbench ETL diagram. This is similar to that shown in Figure 4-4 with details in Figures 4-5 to 4-9.
You install the sakila database by first sourcing the sakila-schema.sql file and then the sakila-data.sql file. For example, the following is using MySQL Shell:
MySQL [localhost+ ssl] SQL> \source sakila-schema.sql MySQL [localhost+ ssl] SQL> \source sakila-data.sql
Add the path to the files if they are not located in the current directory.
Common for the three data sets thus far is that they contain little data. While this is in many cases a nice feature as it makes it easier to work with, in some cases you need a bit more data to explore the difference in query plans. The employees database is an option with more data.
68
It is possible to choose to have the salaries and titles tables partitioned by the year of the from_date column as shown in Listing 4-1.
Listing 4-1. The optional partitioning of the salaries and titles tables PARTITION BY RANGE COLUMNS(from_date)
(PARTITION p01 VALUES LESS THAN ('1985-12-31') ENGINE = InnoDB, PARTITION p02 VALUES LESS THAN ('1986-12-31') ENGINE = InnoDB, PARTITION p03 VALUES LESS THAN ('1987-12-31') ENGINE = InnoDB, PARTITION p04 VALUES LESS THAN ('1988-12-31') ENGINE = InnoDB, PARTITION p05 VALUES LESS THAN ('1989-12-31') ENGINE = InnoDB, Figure 4-10. The tables, views, and routines in the employees database
ChapTer 4 TesT DaTa
PARTITION p06 VALUES LESS THAN ('1990-12-31') ENGINE = InnoDB, PARTITION p07 VALUES LESS THAN ('1991-12-31') ENGINE = InnoDB, PARTITION p08 VALUES LESS THAN ('1992-12-31') ENGINE = InnoDB, PARTITION p09 VALUES LESS THAN ('1993-12-31') ENGINE = InnoDB, PARTITION p10 VALUES LESS THAN ('1994-12-31') ENGINE = InnoDB, PARTITION p11 VALUES LESS THAN ('1995-12-31') ENGINE = InnoDB, PARTITION p12 VALUES LESS THAN ('1996-12-31') ENGINE = InnoDB, PARTITION p13 VALUES LESS THAN ('1997-12-31') ENGINE = InnoDB, PARTITION p14 VALUES LESS THAN ('1998-12-31') ENGINE = InnoDB, PARTITION p15 VALUES LESS THAN ('1999-12-31') ENGINE = InnoDB, PARTITION p16 VALUES LESS THAN ('2000-12-31') ENGINE = InnoDB, PARTITION p17 VALUES LESS THAN ('2001-12-31') ENGINE = InnoDB, PARTITION p18 VALUES LESS THAN ('2002-12-31') ENGINE = InnoDB, PARTITION p19 VALUES LESS THAN (MAXVALUE) ENGINE = InnoDB)
Table 4-1 shows the number of rows and size of the tablespace files for the tables in the employees database (note that the size may vary a little when you load the data). The size assumes you load the non-partitioned data; the partitioned tables are somewhat larger.
By today’s standards, it is still a relatively small amount of data, but it is big enough that you can start to see some performance differences for different query plans.
The views and routines are summarized in Figure 4-11.
Table 4-1. The size of each table in the employees database
Table # Rows Tablespace Size
departments 9 128 kiB
dept_emp 331603 25600 kiB dept_manager 24 128 kiB employees 300024 22528 kiB salaries 2844047 106496 kiB titles 443308 27648 kiB
70
The dept_emp_latest_date and current_dept_emp views are installed together with the tables, whereas the rest of the objects are installed separately in the objects.sql file.
The stored routines come with their own built-in help which you can obtain by using the employees_usage() function or the employees_help() procedure. The latter is shown in Listing 4-2.
Listing 4-2. The built-in help for the stored routines in the employees database mysql> CALL employees_help()\G
*************************** 1. row ***************************
info:
== USAGE ==
====================
PROCEDURE show_departments()
shows the departments with the manager and number of employees per department
FUNCTION current_manager (dept_id)
Shows who is the manager of a given departmennt FUNCTION emp_name (emp_id)
Shows name and surname of a given employee
Figure 4-11. The views and routines in the employees database
ChapTer 4 TesT DaTa
FUNCTION emp_dept_id (emp_id)
Shows the current department of given employee 1 row in set (0.00 sec)
Query OK, 0 rows affected (0.02 sec)
Installation
You can download a ZIP file with the files required for the installation, or you can clone the GitHub repository at https://github.com/datacharmer/test_db. At the time of writing, there is only a single branch named master. If you have downloaded the ZIP file, it will unzip into a directory named test_db-master.
There are several files. The two relevant for installing the employees database in MySQL 8 are employees.sql and employees_partitioned.sql. The difference is whether the salaries and titles tables are partitioned. (There is also employees_
partitioned_5.1.sql which is meant for MySQL 5.1 where the partitioning scheme used in employees_partitioned.sql is not supported.)
The data is loaded by sourcing the .dump files using the SOURCE command. At the time of writing, the SOURCE command is not supported in MySQL Shell, so you will need to use the legacy mysql command-line client to import the data. Go to the directory with the source files, and choose the employees.sql or employees_partitioned.sql file, depending on whether you want to use partitioning or not, for example:
mysql> SOURCE employees.sql
The import takes a little time and completes by showing how long it took:
+---+
| data_load_time_diff | +---+
| 00:01:51 | +---+
1 row in set (0.44 sec)
72
Optionally, you can load some extra views and stored routines by sourcing the objects.sql file:
mysql> SOURCE objects.sql
In addition to the data sets discussed here, there are some other choices to obtain example data to work with.