ich einen Blick in MySQLMySQL Ansicht Abfrage dauert sehr lange zum Laden
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost`
SQL SECURITY DEFINER VIEW `inventory_view` AS
select (case when isnull(`a`.`items_sold`) then 0 else `a`.`items_sold` end) AS `sold_qty`,
(case when isnull(`a`.`items_bought`) then 0 else `a`.`items_bought` end) AS `bought_qty`,
(case when isnull(`a`.`credit`) then 0 else `a`.`credit` end) AS `credit_amount`,
(case when isnull(`a`.`debit`) then 0 else `a`.`debit` end) AS `debit_amount`,
(case when isnull(`tv`.`count`) then 0 else `tv`.`count` end) AS `tranfers`,
(case when isnull(`a`.`inhand`) then 0 else `a`.`inhand` end) AS `balance`,
(case when isnull(`tv`.`count`) then `a`.`inhand` when isnull(`a`.`inhand`) then `tv`.`count` else (`a`.`inhand` + `tv`.`count`) end) AS `in_hand`,
(case when isnull(`a`.`company_id`) then `tv`.`fk_company` else `a`.`company_id` end) AS `company`,
(case when isnull(`a`.`branch_id`) then `tv`.`fk_branch` else `a`.`branch_id` end) AS `branch`,
(case when isnull(`a`.`item_code`) then convert(`tv`.`fk_item_code` using utf8) else convert(`a`.`item_code` using utf8) end) AS `item`,
(case when isnull(`a`.`operator`) then `tv`.`user` else `a`.`operator` end) AS `fk_operator`
from (`transfer_view` `tv` left join `inventory_main` `a` on(((convert(`tv`.`fk_item_code` using utf8) = convert(`a`.`item_code` using utf8)) and (`a`.`operator` = `tv`.`user`))))
union
select (case when isnull(`a`.`items_sold`) then 0 else `a`.`items_sold` end) AS `sold_qty`,
(case when isnull(`a`.`items_bought`) then 0 else `a`.`items_bought` end) AS `bought_qty`,
(case when isnull(`a`.`credit`) then 0 else `a`.`credit` end) AS `credit_amount`,
(case when isnull(`a`.`debit`) then 0 else `a`.`debit` end) AS `debit_amount`,
(case when isnull(`tv`.`count`) then 0 else `tv`.`count` end) AS `tranfers`,
(case when isnull(`a`.`inhand`) then 0 else `a`.`inhand` end) AS `balance`,
(case when isnull(`tv`.`count`) then `a`.`inhand` when isnull(`a`.`inhand`) then `tv`.`count` else (`a`.`inhand` + `tv`.`count`) end) AS `in_hand`,
(case when isnull(`a`.`company_id`) then `tv`.`fk_company` else `a`.`company_id` end) AS `company`,
(case when isnull(`a`.`branch_id`) then `tv`.`fk_branch` else `a`.`branch_id` end) AS `branch`,
(case when isnull(`a`.`item_code`) then convert(`tv`.`fk_item_code` using utf8) else convert(`a`.`item_code` using utf8) end) AS `item`,
(case when isnull(`a`.`operator`) then `tv`.`user` else `a`.`operator` end) AS `fk_operator`
from (`inventory_main` `a` left join `transfer_view` `tv` on(((convert(`tv`.`fk_item_code` using utf8) = convert(`a`.`item_code` using utf8)) and (`a`.`operator` = `tv`.`user`))));
Es hat Tausende von Datensätzen erstellt und führt sehr langsam. Jede Abfrage dauert etwa 50 Sekunden.
Können Sie mir bitte helfen, den Fehler zu finden oder eine bessere Möglichkeit zum Erstellen der Ansicht empfehlen?
Poste das Ganze nicht in einer Zeile. Fügen Sie Zeilenumbrüche hinzu und ziehen Sie sie ein, damit wir sehen können, was sie macht. – Barmar
Die Abfrage sagt uns nichts. Pls enthalten die EXPLAIN-Ergebnisse für die Auswahl und eine Liste aller Indizes und indizierten Spalten in den betroffenen Tabellen. Sie müssen uns auch mitteilen, was Sie aus dem Bericht herausholen möchten (Beispieldaten und die erwartete Ausgabe basierend auf den Beispieldaten wären eine große Hilfe). – Shadow
Was macht die Ansicht? Was ist der Zweck dieser Abfrage? Sie müssen angeben, wofür Sie Hilfe benötigen, so dass die Personen Sie verstehen können, ohne Ihre Perspektive zu haben. Wir sind nicht allwissend in deinem Leben. –