I have a problem with database performance because there are too many joins in the query that was built. I have the initiative to create a table view so that the process becomes faster than before, the code is as below
CREATE VIEW dashboard_sales AS (
SELECT o.order_id,
o.order_date,
o.order_status,
o.order_gender,
o.order_birth_date,
op.op_status,
op.op_payment_code,
oi.oi_qty,
op.op_total,
oi.item_id,
i.item_name,
dc.dc_id,
dc.dc_name,
dc.dc_sales,
c.id_city,
c.name_city,
pc.pc_caption
FROM `order` o
LEFT JOIN order_items oi
ON o.order_id = oi.order_id
LEFT JOIN order_payment op
ON o.order_id = op.order_id
LEFT JOIN item i
ON oi.item_id = i.item_id
LEFT JOIN distribution_channel dc
ON o.dc_id = dc.dc_id
LEFT JOIN city c
ON o.order_city = c.id_city
LEFT JOIN payment_channel pc
ON op.op_payment_code = pc.pc_code
);
but because there are many records and I am looking for a solution that is by adding indexing as below,
CREATE INDEX MyIndex
ON dashboard_sales(op_total, order_date)
but i get some error like this,
#1347 - 'matoa_admin.dashboard_sales' is not BASE TABLE
how to solved this problem? and can it make indexing in the table view?