Just got myself a Asustor NAS to handle my videos, pictures, music and etc. Having both a Desktop and a Notebook in the house, I figured it would be a good idea to setup my database on the NAS (which already comes with MariaDB preinstalled).
The Setup: RAID 1, max read speads of about 110MB/s from the disk, connected via 1.3 Mbps WiFi with gigabit connection. Getting about 60MB/s using BlackMagic Benchmark.
The query:
SELECT items.title, items.discount, items.qtd, items.price, ((price * qtd) - discount) AS total, DATE_FORMAT(orders.created_at, '%m-%y')
FROM items
INNER JOIN orders ON orders.order_id = items.order_id
ORDER BY created_at;
The table orders
has about 1.8k rows, the table items
has about 4.7k rows. The query affects 5k rows and takes between 4.8 to 7.0 seconds to run, which seems absurd for such a simple query. I used to run the same query in my localhost (ok, it is a NVMe SSD, which I get is a lot faster), on milliseconds. order_id
is a VARCHAR with about 10 characters in it.
It took about 7 (9 last time) minutes to insert all the data in all tables:
`orders` - 1.7k rows, 11 columns
`items` - 4.8k rows, 12 columns
`customers` - 1.7k rows, 9 columns
My question:
Thanks a lot.
**Tables:**
`CREATE TABLE `orders` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`order_id` varchar(15) DEFAULT NULL COMMENT 'VA',
`created_at` datetime DEFAULT NULL,
`gateway` varchar(25) DEFAULT NULL,
`total` decimal(15,0) DEFAULT NULL,
`subtotal` decimal(15,0) DEFAULT NULL,
`status` varchar(20) DEFAULT NULL,
`discounts` decimal(15,0) DEFAULT NULL,
`total_price` decimal(15,0) DEFAULT NULL,
`order_number` varchar(15) DEFAULT NULL,
`processing` varchar(15) DEFAULT NULL,
`customer_id` varchar(15) DEFAULT NULL,
`number` varchar(15) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `number` (`number`),
UNIQUE KEY `order_id` (`order_id`),
KEY `customer_id` (`customer_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1712 DEFAULT CHARSET=utf8;`
Yes this is kind of bad performance. Correct indexing for the query will go part way in solving the performance problem of the query. Getting to get the NAS to use innodb_buffer_pool and free memory as disk cache is going to be difficult with only 512M on board.
Correct indexing of tables with help the join and order. Design changes to use integer primary keys for joins. As a first step, if order_id
really isn't utf8 and is just latin1 changing for that column that would make the key smaller, could change this to the primary key too.
As this is an entire two tables data search in the query, its only going to eliminate IO latency if it can all stay in RAM.
Hosted database will offer more RAM, and probably a faster CPU.