我有多个表连接的搜索查询
SELECT
DISTINCT pp.person_profile_id,
pp.middle_name,
pp.prefix,
pp.first_name,
pp.last_name,
pp.suffix,
pp.privacy_type,
pp.gender,
pp.gender_class,
pp.birth_date,
pp.birth_place_id,
pp.death_date,
pp.death_place_id,
pp.profile_photo_s3_path,
pp.profile_photo_size,
pp.created_by,
pp.created_on_date,
pp.updated_by,
pp.updated_on_date,
pp.life_status,
pp.user_id,
pp.deleted_status,
pp.bd_approximation,
pp.bd_year,
pp.bd_month,
pp.bd_season,
pp.dd_approximation,
pp.dd_year,
pp.dd_month,
pp.dd_season,
pp.display_name,
pp.secondary_name,
pp.profile_creation_type,
date_format(pp.birth_date, '%b %d, %Y') as formated_birth_date,
date_format(pp.death_date, '%b %d, %Y') as formated_death_date,
(
CASE
WHEN pp.display_name IS NOT NULL THEN pp.display_name
ELSE trim(
concat(
COALESCE(pp.first_name, ''),
' ',
COALESCE(pp.middle_name, ''),
' ',
COALESCE(pp.last_name, '')
)
)
END
) final_person_name
FROM
tbl_person_profile AS pp
LEFT JOIN tbl_address as ba ON pp.birth_place_id = ba.id
OR pp.death_place_id = ba.id
LEFT JOIN tbl_address_book as a ON pp.person_profile_id = a.person_profile_id
AND a.is_active = '1'
LEFT JOIN tbl_address as ad ON a.address_id = ad.id
AND ad.deleted_status = '0'
LEFT JOIN tbl_person_relationships as prf ON pp.person_profile_id = prf.focus_person_id
OR pp.person_profile_id = prf.related_person_id
LEFT JOIN tbl_additional_names as an ON pp.person_profile_id = an.person_profile_id
LEFT JOIN tbl_person_profile_storytelling as pps ON pp.person_profile_id = pps.person_profile_id
AND pps.deleted_status = '0'
LEFT JOIN tbl_person_profile as storytelling_person ON find_in_set(
storytelling_person.person_profile_id,
pps.story_writer_ids
) > 0
AND storytelling_person.deleted_status = '0'
LEFT JOIN tbl_indexer_vital_record as ivr ON (
pp.person_profile_id = ivr.person_profile_id
OR find_in_set(pp.person_profile_id, ivr.provider_value) > 0
OR find_in_set(pp.person_profile_id, ivr.attendees_value) > 0
OR find_in_set(pp.person_profile_id, ivr.contact_person_value) > 0
OR find_in_set(pp.person_profile_id, ivr.focus_person_value) > 0
OR find_in_set(pp.person_profile_id, ivr.death_attendees_value) > 0
OR find_in_set(pp.person_profile_id, ivr.death_attendant_value) > 0
)
LEFT JOIN tbl_indexer_location as il ON pp.person_profile_id = il.person_profile_id
OR (
find_in_set(pp.person_profile_id, il.profile_value) > 0
AND il.profile_key = 'Person'
)
AND il.deleted_status = '0'
LEFT JOIN tbl_indexer_physical_apperance as ipa ON (
pp.person_profile_id = ipa.person_profile_id
OR find_in_set(pp.person_profile_id, ipa.artist_value) > 0
OR find_in_set(pp.person_profile_id, ipa.focus_person_value) > 0
)
LEFT JOIN tbl_indexer_event_details as ied ON (
pp.person_profile_id = ied.person_profile_id
OR find_in_set(pp.person_profile_id, ied.union_partner_value) > 0
OR find_in_set(pp.person_profile_id, ied.officiant_value) > 0
OR find_in_set(pp.person_profile_id, ied.attendees_value) > 0
OR find_in_set(pp.person_profile_id, ied.focus_person_value) > 0
)
LEFT JOIN tbl_event_vendor as ev_search ON find_in_set(ev_search.id, ied.event_vendor) > 0
LEFT JOIN tbl_event_organizer as eo_search ON find_in_set(eo_search.id, ied.event_organizer) > 0
LEFT JOIN tbl_person_profile as ppe ON (
find_in_set(ppe.person_profile_id, ied.union_partner_value) > 0
OR find_in_set(ppe.person_profile_id, ied.officiant_value) > 0
OR find_in_set(ppe.person_profile_id, ied.attendees_value) > 0
OR find_in_set(ppe.person_profile_id, ied.focus_person_value) > 0
OR find_in_set(ppe.person_profile_id, ivr.provider_value) > 0
OR find_in_set(ppe.person_profile_id, ivr.attendees_value) > 0
OR find_in_set(ppe.person_profile_id, ivr.contact_person_value) > 0
OR find_in_set(ppe.person_profile_id, ivr.focus_person_value) > 0
OR find_in_set(ppe.person_profile_id, ivr.death_attendees_value) > 0
OR find_in_set(ppe.person_profile_id, ivr.death_attendant_value) > 0
OR find_in_set(ppe.person_profile_id, ipa.artist_value) > 0
OR find_in_set(ppe.person_profile_id, ipa.focus_person_value) > 0
OR (
find_in_set(
ppe.person_profile_id,
ev_search.vendor_name_value
) > 0
AND ev_search.vendor_name_key = 'Person'
)
OR find_in_set(
ppe.person_profile_id,
ev_search.contact_person_value
) > 0
OR (
find_in_set(
ppe.person_profile_id,
eo_search.event_organizer_value
) > 0
AND eo_search.event_organizer_key = 'Person'
)
OR find_in_set(
ppe.person_profile_id,
eo_search.contact_person_value
) > 0
)
AND ppe.deleted_status = '0'
LEFT JOIN tbl_event_vendor as ev ON pp.person_profile_id = ev.vendor_name_value
AND ev.vendor_name_key = 'Person'
AND ev.vendor_location_key = 'Map'
LEFT JOIN tbl_location_profile as locp ON (
find_in_set(locp.location_profile_id, il.location_value) > 0
OR find_in_set(locp.location_profile_id, ied.location_info_value) > 0
OR find_in_set(locp.location_profile_id, ied.ceremony_value) > 0
OR find_in_set(locp.location_profile_id, ied.reception_value) > 0
OR find_in_set(locp.location_profile_id, ivr.location_value) > 0
OR find_in_set(
locp.location_profile_id,
ivr.death_location_value
) > 0
OR find_in_set(locp.location_profile_id, ipa.location_value) > 0
OR find_in_set(
locp.location_profile_id,
ev_search.vendor_location_value
) > 0
)
AND locp.deleted_status = '0'
LEFT JOIN tbl_company_profile as cp ON find_in_set(cp.company_profile_id, ipa.company_value) > 0
OR (
find_in_set(
cp.company_profile_id,
ev_search.vendor_name_value
) > 0
AND ev_search.vendor_name_key = 'Company'
)
OR (
find_in_set(
cp.company_profile_id,
eo_search.event_organizer_value
) > 0
AND eo_search.event_organizer_key = 'Company'
)
AND cp.deleted_status = '0'
WHERE
pp.user_id = 540
AND pp.catalog_id = 320
AND pp.deleted_status != '1'
AND (
pp.display_name LIKE '%living%'
OR pp.prefix LIKE '%living%'
OR pp.suffix LIKE '%living%'
OR pp.first_name LIKE '%living%'
OR pp.last_name LIKE '%living%'
OR pp.middle_name LIKE '%living%'
OR concat_ws(' ', pp.first_name, pp.last_name) LIKE '%living%'
OR concat_ws(' ', pp.first_name, pp.middle_name, pp.last_name) LIKE '%living%'
OR pp.privacy_type LIKE '%living%'
OR pp.gender LIKE '%living%'
OR pp.life_status LIKE '%living%'
OR pp.display_name LIKE '%living%'
OR pp.secondary_name LIKE '%living%'
OR pp.lds_number LIKE '%living%'
OR pp.bd_approximation LIKE '%living%'
OR pp.bd_year LIKE '%living%'
OR pp.bd_month LIKE '%living%'
OR pp.bd_season LIKE '%living%'
OR pp.dd_approximation LIKE '%living%'
OR pp.dd_year LIKE '%living%'
OR pp.dd_month LIKE '%living%'
OR pp.dd_year LIKE '%living%'
OR pp.dd_season LIKE '%living%'
OR DATE(pp.birth_date) LIKE '%living%'
OR DATE(pp.death_date) LIKE '%living%'
OR ba.current_address LIKE '%living%'
OR ba.vintage_address LIKE '%living%'
OR ba.vintage_address_notes LIKE '%living%'
OR ba.country LIKE '%living%'
OR ba.state LIKE '%living%'
OR ba.state LIKE '%living%'
OR ba.state LIKE '%living%'
OR ba.zipcode LIKE '%living%'
OR ba.street_address LIKE '%living%'
OR ba.neighborhood LIKE '%living%'
OR ba.county LIKE '%living%'
OR ba.note LIKE '%living%'
OR a.email LIKE '%living%'
OR a.mobile_no LIKE '%living%'
OR a.phone_no LIKE '%living%'
OR a.address_type LIKE '%living%'
OR a.lds_number LIKE '%living%'
OR a.web_address LIKE '%living%'
OR ad.current_address LIKE '%living%'
OR ad.vintage_address LIKE '%living%'
OR ad.vintage_address_notes LIKE '%living%'
OR ad.country LIKE '%living%'
OR ad.state LIKE '%living%'
OR ad.city LIKE '%living%'
OR ad.zipcode LIKE '%living%'
OR ad.street_address LIKE '%living%'
OR ad.neighborhood LIKE '%living%'
OR ad.county LIKE '%living%'
OR ad.note LIKE '%living%'
OR prf.family_or_nonfamily LIKE '%living%'
OR prf.connection_type LIKE '%living%'
OR prf.focus_person_to_related_person_relation_specific_role LIKE '%living%'
OR prf.focus_person_to_related_person_relation_family_side LIKE '%living%'
OR prf.focus_person_to_related_person_relation_sibling_type LIKE '%living%'
OR prf.focus_person_to_related_person_relation_multiple_birth_type_type LIKE '%living%'
OR prf.focus_person_to_related_person_relation_zygosity LIKE '%living%'
OR prf.focus_person_to_related_person_relation_donor_surrogate LIKE '%living%'
OR prf.focus_person_to_related_person_relation_donor_conceived LIKE '%living%'
OR prf.focus_person_to_related_person_relation_gestational_type LIKE '%living%'
OR prf.related_person_to_focus_person_relation_role LIKE '%living%'
OR prf.related_person_to_focus_person_relation_specific_role LIKE '%living%'
OR prf.related_person_to_focus_person_relation_family_side LIKE '%living%'
OR prf.related_person_to_focus_person_relation_sibling_type LIKE '%living%'
OR prf.related_person_to_focus_person_relation_multiple_birth_type_type LIKE '%living%'
OR prf.related_person_to_focus_person_relation_zygosity LIKE '%living%'
OR prf.related_person_to_focus_person_relation_donor_surrogate LIKE '%living%'
OR prf.related_person_to_focus_person_relation_donor_conceived LIKE '%living%'
OR prf.related_person_to_focus_person_relation_gestational_type LIKE '%living%'
OR prf.relationship_status LIKE '%living%'
OR an.prefix LIKE '%living%'
OR an.first_name LIKE '%living%'
OR an.last_name LIKE '%living%'
OR an.middle_name LIKE '%living%'
OR an.suffix LIKE '%living%'
OR an.type LIKE '%living%'
OR an.notes LIKE '%living%'
OR an.birth_approximation LIKE '%living%'
OR an.birth_year LIKE '%living%'
OR an.birth_month LIKE '%living%'
OR an.birth_season LIKE '%living%'
OR concat_ws(' ', an.first_name, an.last_name) LIKE '%living%'
OR concat_ws(' ', an.first_name, an.middle_name, an.last_name) LIKE '%living%'
OR pps.caption LIKE '%living%'
OR pps.storytelling LIKE '%living%'
OR pps.story_writer LIKE '%living%'
OR pps.record_audio_name LIKE '%living%'
OR pps.recorded_audio_transcription LIKE '%living%'
OR pps.upload_audio_name LIKE '%living%'
OR pps.uploaded_audio_transcription LIKE '%living%'
OR concat_ws(
' ',
storytelling_person.first_name,
storytelling_person.middle_name,
storytelling_person.last_name
) LIKE '%living%'
OR storytelling_person.display_name LIKE '%living%'
OR ivr.indexer_header_type LIKE '%living%'
OR ivr.indexer_header_sub_type LIKE '%living%'
OR ivr.birth_time LIKE '%living%'
OR ivr.death_time LIKE '%living%'
OR ivr.date LIKE '%living%'
OR ivr.death_date LIKE '%living%'
OR ivr.date_approximation LIKE '%living%'
OR ivr.date_year LIKE '%living%'
OR ivr.date_month LIKE '%living%'
OR ivr.date_season LIKE '%living%'
OR ivr.death_approximation LIKE '%living%'
OR ivr.death_year LIKE '%living%'
OR ivr.death_month LIKE '%living%'
OR ivr.death_season LIKE '%living%'
OR ivr.birth_gender LIKE '%living%'
OR ivr.birth_type LIKE '%living%'
OR ivr.birth_presentation LIKE '%living%'
OR ivr.facility LIKE '%living%'
OR ivr.death_cause LIKE '%living%'
OR ivr.disposition_method LIKE '%living%'
OR ivr.disposition_sub_method LIKE '%living%'
OR ivr.is_embalmed LIKE '%living%'
OR ivr.section LIKE '%living%'
OR ivr.plot LIKE '%living%'
OR ivr.inscription LIKE '%living%'
OR ivr.reason LIKE '%living%'
OR ivr.age LIKE '%living%'
OR ivr.height LIKE '%living%'
OR ivr.weight LIKE '%living%'
OR concat_ws(' ', ivr.age, ivr.age_measure) LIKE '%living%'
OR concat_ws(' ', ivr.height, ivr.height_measure) LIKE '%living%'
OR concat_ws(' ', ivr.weight, ivr.weight_measure) LIKE '%living%'
OR ivr.eye_color LIKE '%living%'
OR ivr.hair_color LIKE '%living%'
OR ivr.skin_color LIKE '%living%'
OR ivr.handed LIKE '%living%'
OR ivr.blood_type LIKE '%living%'
OR ivr.gender LIKE '%living%'
OR ivr.physical_description LIKE '%living%'
OR ivr.subtopic LIKE '%living%'
OR ivr.ethnicity LIKE '%living%'
OR ivr.sexual_orientation LIKE '%living%'
OR ivr.timeline_source LIKE '%living%'
OR ivr.personal_id_number LIKE '%living%'
OR ivr.location_value LIKE '%living%'
OR ivr.death_location_value LIKE '%living%'
OR ivr.death_location_value LIKE '%living%'
OR ivr.notes LIKE '%living%'
OR ivr.indexer_vital_record_notes LIKE '%living%'
OR ivr.death_notes LIKE '%living%'
OR ivr.provider_value LIKE '%living%'
OR ivr.attendees_value LIKE '%living%'
OR ivr.contact_person_value LIKE '%living%'
OR ivr.death_attendant_value LIKE '%living%'
OR ivr.death_attendees_value LIKE '%living%'
OR ivr.focus_person_value LIKE '%living%'
OR il.indexer_header_type LIKE '%living%'
OR il.indexer_header_sub_type LIKE '%living%'
OR il.acquisition_type LIKE '%living%'
OR il.start_date LIKE '%living%'
OR il.end_date LIKE '%living%'
OR il.start_date_approximation LIKE '%living%'
OR il.start_date_year LIKE '%living%'
OR il.start_date_month LIKE '%living%'
OR il.start_date_season LIKE '%living%'
OR il.end_date_approximation LIKE '%living%'
OR il.end_date_year LIKE '%living%'
OR il.end_date_month LIKE '%living%'
OR il.end_date_season LIKE '%living%'
OR il.relationship_to_location LIKE '%living%'
OR il.timeline_source LIKE '%living%'
OR il.location_type LIKE '%living%'
OR il.location_sub_type LIKE '%living%'
OR il.name_company LIKE '%living%'
OR il.reason LIKE '%living%'
OR il.type_of_build LIKE '%living%'
OR il.location_value LIKE '%living%'
OR il.notes LIKE '%living%'
OR il.location_notes LIKE '%living%'
OR locp.location_name LIKE '%living%'
OR ipa.indexer_header_type LIKE '%living%'
OR ipa.indexer_header_sub_type LIKE '%living%'
OR ipa.location_on_body LIKE '%living%'
OR ipa.side_of_body LIKE '%living%'
OR ipa.label LIKE '%living%'
OR ipa.start_date LIKE '%living%'
OR ipa.end_date LIKE '%living%'
OR ipa.start_date_approximation LIKE '%living%'
OR ipa.start_date_year LIKE '%living%'
OR ipa.start_date_month LIKE '%living%'
OR ipa.start_date_season LIKE '%living%'
OR ipa.end_date_approximation LIKE '%living%'
OR ipa.end_date_year LIKE '%living%'
OR ipa.end_date_month LIKE '%living%'
OR ipa.end_date_season LIKE '%living%'
OR ipa.method LIKE '%living%'
OR ipa.style LIKE '%living%'
OR ipa.status LIKE '%living%'
OR ipa.story LIKE '%living%'
OR ipa.timeline_source LIKE '%living%'
OR ipa.location_value LIKE '%living%'
OR ipa.notes LIKE '%living%'
OR ipa.company_value LIKE '%living%'
OR ipa.artist_value LIKE '%living%'
OR ipa.focus_person_value LIKE '%living%'
OR ipa.focus_person_value LIKE '%living%'
OR cp.company_name LIKE '%living%'
OR ied.event_type LIKE '%living%'
OR ied.event_sub_type LIKE '%living%'
OR ied.event_name LIKE '%living%'
OR ied.indexer_header_type LIKE '%living%'
OR ied.indexer_header_sub_type LIKE '%living%'
OR ied.start_date LIKE '%living%'
OR ied.end_date LIKE '%living%'
OR ied.start_date_approximation LIKE '%living%'
OR ied.start_date_year LIKE '%living%'
OR ied.start_date_month LIKE '%living%'
OR ied.start_date_season LIKE '%living%'
OR ied.end_date_approximation LIKE '%living%'
OR ied.end_date_year LIKE '%living%'
OR ied.end_date_month LIKE '%living%'
OR ied.end_date_season LIKE '%living%'
OR ied.ceremony_type LIKE '%living%'
OR ied.union_type LIKE '%living%'
OR ied.location_type LIKE '%living%'
OR ied.timeline_source LIKE '%living%'
OR ied.location_info_value LIKE '%living%'
OR ied.notes LIKE '%living%'
OR ied.service_type LIKE '%living%'
OR ppe.display_name LIKE '%living%'
OR concat_ws(' ', ppe.first_name, ppe.middle_name, ppe.last_name) LIKE '%living%'
OR concat_ws(' ', ppe.first_name, ppe.last_name) LIKE '%living%'
OR ppe.first_name LIKE '%living%'
OR ppe.middle_name LIKE '%living%'
OR ppe.last_name LIKE '%living%'
OR ied.attendees_value LIKE '%living%'
OR ied.union_partner_value LIKE '%living%'
OR ied.officiant_value LIKE '%living%'
OR locp.location_name LIKE '%living%'
OR ied.ceremony_value LIKE '%living%'
OR ied.reception_value LIKE '%living%'
OR ev_search.vendor_name_value LIKE '%living%'
OR ev_search.contact_person_value LIKE '%living%'
OR ev_search.vendor_location_value LIKE '%living%'
OR ev_search.service_type LIKE '%living%'
OR eo_search.event_organizer_value LIKE '%living%'
OR eo_search.contact_person_value LIKE '%living%'
OR ev.vendor_location_value LIKE '%living%'
OR ev.service_type LIKE '%living%'
)
此查询适用于较少的记录,但对于较大的记录,它会破坏系统。
我用谷歌搜索了很多东西,发现索引是解决方案之一,所以考虑添加以下索引
tbl_person_profile-
CREATE INDEX idx_person_profile_user_id ON tbl_person_profile (user_id);
CREATE INDEX idx_person_profile_catalog_id ON tbl_person_profile (catalog_id);
CREATE INDEX idx_person_profile_deleted_status ON tbl_person_profile (deleted_status);
CREATE INDEX idx_person_profile_id ON tbl_person_profile (person_profile_id);
CREATE INDEX idx_person_profile_birth_place ON tbl_person_profile (birth_place_id);
CREATE INDEX idx_person_profile_death_place ON tbl_person_profile (death_place_id);
CREATE FULLTEXT INDEX idx_person_profile_display_name ON tbl_person_profile (display_name);
CREATE FULLTEXT INDEX idx_person_profile_names ON tbl_person_profile (first_name, middle_name, last_name);
CREATE FULLTEXT INDEX idx_person_profile_secondary_name ON tbl_person_profile (secondary_name);
CREATE FULLTEXT INDEX idx_person_profile_gender ON tbl_person_profile (gender);
CREATE FULLTEXT INDEX idx_person_profile_life_status ON tbl_person_profile (life_status);
tbl_address-
CREATE INDEX idx_address_id ON tbl_address (id);
CREATE INDEX idx_address_deleted_status ON tbl_address (deleted_status);
CREATE FULLTEXT INDEX idx_address_current ON tbl_address (current_address);
CREATE FULLTEXT INDEX idx_address_vintage ON tbl_address (vintage_address);
CREATE FULLTEXT INDEX idx_address_country_state_zip ON tbl_address (country, state, zipcode);
CREATE FULLTEXT INDEX idx_address_street_neighborhood_county ON tbl_address (street_address, neighborhood, county);
tbl_address_book-
CREATE INDEX idx_address_book_person_id ON tbl_address_book (person_profile_id);
CREATE INDEX idx_address_book_is_active ON tbl_address_book (is_active);
CREATE INDEX idx_address_book_address_id ON tbl_address_book (address_id);
tbl_person_relationships-
CREATE INDEX idx_person_relationships_focus_person_id ON tbl_person_relationships (focus_person_id);
CREATE INDEX idx_person_relationships_related_person_id ON tbl_person_relationships (related_person_id);
CREATE FULLTEXT INDEX idx_person_relationships_family_nonfamily ON tbl_person_relationships (family_or_nonfamily);
CREATE FULLTEXT INDEX idx_person_relationships_connection_type ON tbl_person_relationships (connection_type);
tbl_additional_names-
CREATE INDEX idx_additional_names_person_id ON tbl_additional_names (person_profile_id);
CREATE FULLTEXT INDEX idx_additional_names ON tbl_additional_names (first_name, middle_name, last_name);
CREATE FULLTEXT INDEX idx_additional_names_type ON tbl_additional_names (type);
CREATE FULLTEXT INDEX idx_additional_names_notes ON tbl_additional_names (notes);
tbl_person_profile_storytelling-
CREATE INDEX idx_storytelling_person_id ON tbl_person_profile_storytelling (person_profile_id);
CREATE INDEX idx_storytelling_deleted_status ON tbl_person_profile_storytelling (deleted_status);
CREATE FULLTEXT INDEX idx_storytelling_caption ON tbl_person_profile_storytelling (caption);
CREATE FULLTEXT INDEX idx_storytelling_story ON tbl_person_profile_storytelling (storytelling);
tbl_indexer_vital_record-
CREATE INDEX idx_vital_record_person_id ON tbl_indexer_vital_record (person_profile_id);
CREATE FULLTEXT INDEX idx_vital_record_type ON tbl_indexer_vital_record (indexer_header_type, indexer_header_sub_type);
CREATE FULLTEXT INDEX idx_vital_record_notes ON tbl_indexer_vital_record (notes, indexer_vital_record_notes, death_notes);
tbl_indexer_location-
CREATE INDEX idx_location_person_id ON tbl_indexer_location (person_profile_id);
CREATE INDEX idx_location_deleted_status ON tbl_indexer_location (deleted_status);
CREATE FULLTEXT INDEX idx_location_value ON tbl_indexer_location (location_value);
tbl_indexer_physical_apperance-
CREATE INDEX idx_physical_apperance_person_id ON tbl_indexer_physical_apperance (person_profile_id);
CREATE FULLTEXT INDEX idx_physical_apperance_location ON tbl_indexer_physical_apperance (location_on_body);
CREATE FULLTEXT INDEX idx_physical_apperance_story ON tbl_indexer_physical_apperance (story);
tbl_indexer_event_details-
CREATE INDEX idx_event_details_person_id ON tbl_indexer_event_details (person_profile_id);
CREATE FULLTEXT INDEX idx_event_details_type ON tbl_indexer_event_details (event_type, event_sub_type);
CREATE FULLTEXT INDEX idx_event_details_notes ON tbl_indexer_event_details (notes);
tbl_event_vendor-
CREATE INDEX idx_event_vendor_id ON tbl_event_vendor (id);
CREATE FULLTEXT INDEX idx_event_vendor_name ON tbl_event_vendor (vendor_name_value, vendor_name_key);
CREATE FULLTEXT INDEX idx_event_vendor_location ON tbl_event_vendor (vendor_location_value);
tbl_event_organizer-
CREATE INDEX idx_event_organizer_id ON tbl_event_organizer (id);
CREATE FULLTEXT INDEX idx_event_organizer_name ON tbl_event_organizer (event_organizer_value, event_organizer_key);
tbl_location_profile-
CREATE INDEX idx_location_profile_id ON tbl_location_profile (location_profile_id);
CREATE INDEX idx_location_profile_deleted_status ON tbl_location_profile (deleted_status);
CREATE FULLTEXT INDEX idx_location_profile_name ON tbl_location_profile (location_name);
tbl_company_profile-
CREATE INDEX idx_company_profile_id ON tbl_company_profile (company_profile_id);
CREATE INDEX idx_company_profile_deleted_status ON tbl_company_profile (deleted_status);
CREATE FULLTEXT INDEX idx_company_profile_name ON tbl_company_profile (company_name);
tbl_person_profile_storytelling-
CREATE INDEX idx_storytelling_person_id ON tbl_person_profile (person_profile_id);
CREATE INDEX idx_storytelling_person_deleted_status ON tbl_person_profile (deleted_status);
CREATE FULLTEXT INDEX idx_storytelling_person_names ON tbl_person_profile (first_name, middle_name, last_name);
请建议我如何优化和提高上述查询性能。
谢谢。
堵嘴!!
JOINs
不是问题,带有前导通配符的 OR
和 LIKE
才是问题。 FIND_IN_SET()
也是如此。 和 DATE() ——参见 sargable。也许DISTINCT
。
部分解决方案是使用所有 text 创建另一列,并在该列上添加
FULLTEXT
索引,然后执行类似的操作
WHERE MATCH(ft) AGAINST('living' IN BOOLEAN MODE)
但是,请务必阅读全文的局限性。
畏缩! 根据用户输入检查各种数字和日期列。 您的应用程序可以查看数据条目并查看它是日期、数字还是字符串。 然后,使用三个查询之一;每个测试都只有数字、日期或文本测试。
完成大部分工作,然后让我们再看一遍。