Closed janis-rullis closed 4 years ago
owner_id
-index. https://github.com/janis-rullis/pr1/wiki/Uses-cases-and-Conditions
product
type
-enum, maybe a an index if need to filter a type relation
Unsigned, indexes.
root
user, enable logs, execute API requests, click in the chart so that the time-range window appears, select a range +/- an hour and press analyze.user
before improvementsEXPLAIN SELECT t0.id AS id_1, t0.name AS name_2, t0.surname AS surname_3, t0.balance AS balance_4 FROM user t0;
user
improvementsALTER TABLE`user`
CHANGE `balance` `balance` smallint(5) unsigned NOT NULL DEFAULT '10000' COMMENT 'All users upon creation have $100 in their balance. #8';
balance
- size is more fitting, has an initial value and a comment.Not broken. Returns
{
"id": 4,
"name": "John",
"surname": "Doe",
"balance": 10000
}
Green.
relation
before improvementsEXPLAIN
SELECT
t0.id AS id_1,
t0.owner_id AS owner_id_2,
t0.order_id AS order_id_3,
t0.product_id AS product_id_4,
t0.quantity AS quantity_5
FROM
relation t0
WHERE
t0.order_id = 1 AND t0.owner_id = 1
order
before improvementsSELECT
t0.id AS id_1,
t0.owner_id AS owner_id_2,
t0.name AS name_3,
t0.surname AS surname_4,
t0.street AS street_5,
t0.country AS country_6,
t0.phone AS phone_7,
t0.state AS state_8,
t0.zip AS zip_9,
t0.production_cost AS production_cost_10,
t0.shipping_cost AS shipping_cost_11,
t0.express_shipping AS express_shipping_12,
t0.total_cost AS total_cost_13
FROM
`order` t0
WHERE
t0.owner_id = 1
ALTER TABLE`relation`
CHANGE `owner_id` `owner_id` int(11) UNSIGNED NOT NULL,
CHANGE `order_id` `order_id` int(11) UNSIGNED NOT NULL,
CHANGE `product_id` `product_id` int(11) UNSIGNED NOT NULL,
CHANGE `quantity` `quantity` int(11) UNSIGNED NOT NULL
ALTER TABLE`relation`
ADD INDEX `owner_order` (`owner_id`, `order_id`);
Works.
Green.
order
improvementsALTER TABLE`order`
CHANGE `owner_id` `owner_id` int(11) UNSIGNED NOT NULL,
CHANGE `express_shipping` `express_shipping` tinyint(1) UNSIGNED DEFAULT NULL,
CHANGE `production_cost` `production_cost` int(11) UNSIGNED NOT NULL,
CHANGE `shipping_cost` `shipping_cost` int(11) UNSIGNED NOT NULL,
CHANGE `total_cost` `total_cost` int(11) UNSIGNED NOT NULL;
ALTER TABLE `order`
ADD INDEX `owner_id` (`owner_id`);
Green.
product
before improvementsEXPLAIN
SELECT
t0.id AS id_1,
t0.owner_id AS owner_id_2,
t0.type AS type_3,
t0.title AS title_4,
t0.sku AS sku_5,
t0.cost AS cost_6
FROM
product t0
WHERE
t0.owner_id = 1;
product
improvementsbecause this will allow more POSITIVE values, also decrease the cost to SMALLINT
ALTER TABLE`product`
CHANGE `owner_id` `owner_id` int(11) UNSIGNED NOT NULL,
CHANGE `cost` `cost` SMALLINT(5) UNSIGNED NOT NULL COMMENT 'Limited to smallint because user cant afford nothing more than 10000 (see users init balance) #8 #9 ';
ALTER TABLE `product`
ADD INDEX `owner_id` (`owner_id`),
ADD UNIQUE INDEX `sku` (`sku`);
Works.
Green.
https://github.com/lauris-printify/homework-v3/blob/master/docker/backup/mysql/api.sql