Ich habe versucht, die MySQL-Abfrage unten ohne Erfolg zu optimieren. Es dauert noch bis zu 3 Sekunden auszuführen:UNION ODER UNION ALLE MYSQL OPTIMIERUNG
select count(DISTINCT v.id) from
(
select sub_jobs.id from sub_jobs, main_jobs where sub_jobs.title LIKE '%abc%' and main_jobs.id=sub_jobs.parent_id
UNION ALL
select sub_jobs.id from sub_jobs, main_jobs where job_title LIKE '%abc%' and main_jobs.id=sub_jobs.parent_id
UNION ALL
select sub_jobs.id from sub_jobs, main_jobs, companies where companies.company_name LIKE '%abc%' and main_jobs.company_id=companies.id and main_jobs.id=sub_jobs.parent_id
)
as v
Was will ich tun:
- Suchen drei Spalten in 3 Tabellen für ein Keyword und geben die Distinct Count
Grundlegende Tabellenstruktur:
1. sub_jobs
- id
- Titel
- PARENT_ID
- id
- job_title [i dieser Spalte suchen möchten]
- company_id [einige Zeilen einen Eintrag für diese Spalte]
2. main_jobs [Ich will t o suchen diese Spalte]
3. Unternehmen
- id
- company_name [Ich möchte nicht suchen haben diese Spalte]
ERKLÄREN
------column titles------
id
select_type:
table
type
possible_keys
key
key_len
ref
rows
Extra
--- row 1 ----
id: 1
select_type: PRIMARY
table: <derived2>
ALL
NULL
NULL
NULL
NULL
102642
NULL
---- row 2 ----
id: 2
select_type: DERIVED
table: main_jobs
index
PRIMARY,id_index,id_industry_featured_index
id_index
4
NULL
34214
Using index
---- row 3 ----
id: 2
select_type: DERIVED
table: sub_jobs
ref
parent_id,parent_id_category_index
parent_id
4
myjobmag_myjobdb.main_jobs.id
1
Using where
---- row 4 ----
id: 3
select_type: UNION
table: main_jobs
ALL
PRIMARY,id_index,id_industry_featured_index
NULL
NULL
NULL
34214
Using where
---- row 5 ----
id: 3
select_type: UNION
table: sub_jobs
ref
parent_id,parent_id_category_index
parent_id
4
main_jobs.id
1
Using index
---- row 6 ----
id: 4
select_type: UNION
table: main_jobs
ALL
PRIMARY,id_index,id_industry_featured_index
NULL
NULL
NULL
34214
NULL
---- row 7 ----
id: 4
select_type: UNION
table: companies
eq_ref
PRIMARY
PRIMARY
4
main_jobs.company_id
1
Using where
---- row 8 ----
id: 4
select_type: UNION
table: sub_jobs
ref
parent_id,parent_id_category_index
parent_id
4
main_jobs.id
1
Using index
---- row 9 ----
id: NULL
select_type: UNION RESULT
table: <union2,3,4>
ALL
NULL
NULL
NULL
NULL
NULL
Using temporary
Ich habe versucht, UNION ohne die DISTINCT ohne signifikante Gewinne zu verwenden.
Wie kann ich die Laufzeit dieser Abfrage reduzieren.
Vielen Dank für Ihre Hilfe Plan ein Blick auf, erklären. Keine sichtbare Veränderung. –