# Skipping the Sorting Operation for `MergeJoin` Operator by Using Indexes

```
tidb> CREATE TABLE `employees` (
   -> `emp_no` int(11) NOT NULL,
   -> `birth_date` date NOT NULL,
   -> `first_name` varchar(14) NOT NULL,
   -> `last_name` varchar(16) NOT NULL,
   -> `gender` enum('M','F') NOT NULL,
   -> `hire_date` date NOT NULL,
   -> PRIMARY KEY(~!@`emp_no`@!~));
Query OK, 0 rows affected (0.15 sec)

tidb> CREATE TABLE `salaries` (
   -> `emp_no` int(11) NOT NULL,
   -> `salary` int(11) NOT NULL,
   -> `from_date` date NOT NULL,
   -> `to_date` date NOT NULL,
   -> PRIMARY KEY (~!@`emp_no`@!~,`from_date`));
Query OK, 0 rows affected (0.13 sec)
```
------------------------------------------------------------------------------
In the code shown in the slides, a primary key index `PRIMARY KEY (emp_no)` was added to the `employees` table, and a composite primary key index `PRIMARY KEY (emp_no, from_date)` was added to the `salaries` table. Both tables use clustered indexes, allowing the data to be read in the order of the key values. This means the data is already sorted by the join column, eliminating the need for additional sorting operations.