I'm trying to search in multiple tables. I followed normalization rules in designing my database. I have 7 tables explained in this schema.
I built a view to get the interesting columns out of these tables.
ALTER ALGORITHM = UNDEFINED DEFINER = `root`@`localhost` SQL SECURITY DEFINER VIEW `port_data_view` AS
SELECT `s`.`tel_subscriber_number` AS `phone`
,`s`.`tel_subscriber_name` AS `tel_subscriber_name`
,`thp`.`tel_subscriber_has_port_startdate` AS `Reservation_Date`
,`p`.`port_serialnum` AS `port_number`
,`p`.`port_current_speed` AS `port_speed`
,`p`.`idport` AS `idport`
,`p`.`port_status` AS `port_status`
,`isp`.`isp_en_name` AS `isp_en_name`
,`c`.`contract_enname` AS `contract_enname`
,`mdf`.`mdf_room_arname` AS `mdf_room_arname`
,`mdf`.`idmdf_room` AS `idmdf_room`
,`c`.`idcontract` AS `contract_id`
,`isp`.`idisp` AS `isp_id`
FROM (
(
(
(
(
(
`tel_subscriber` `s` INNER JOIN `tel_subscriber_has_port` `thp` ON (
(
(`s`.`idtel_subscriber` = `thp`.`tel_subscriber_idtel_subscriber`)
AND (`thp`.`tel_subscriber_has_port_status` = 'active')
)
)
) INNER JOIN `port` `p` ON ((`p`.`idport` = `thp`.`port_idport`))
) INNER JOIN `isp_has_port` `ihp` ON (
(
(`p`.`idport` = `ihp`.`port_idport`)
AND (`ihp`.`isp_has_port_status` = 'Active')
)
)
) INNER JOIN `isp` ON ((`ihp`.`isp_idisp` = `isp`.`idisp`))
) INNER JOIN `mdf_room` `mdf` ON ((`mdf`.`idmdf_room` = `p`.`mdf_room_idmdf_room`))
) INNER JOIN `contract` `c` ON ((`c`.`idcontract` = `p`.`contract_idcontract`))
)
as you can see there is 7 joins between these tables. when I try to search in this view about any factor (1 or multiple criteria), it's too slow (more than 10 minutes with no result). when I try to search in each table I get the result with maximum time of 5 seconds. The count of records in each table are:
- mdf_room: 538
- tel_subscriber: 798019
- tel_subscriber_has_port: 790989
- port: 797174
- isp: 22
- isp_has_port: 810676
- contract: 25
I tried to explain the query in here.
what can I do to search with a proper time about the information I want?