sql-improvement's Introduction
Ways to improve sql query SELECT Jobs.id AS `Jobs__id`, Jobs.name AS `Jobs__name`, Jobs.media_id AS `Jobs__media_id`, Jobs.job_category_id AS `Jobs__job_category_id`, Jobs.job_type_id AS `Jobs__job_type_id`, Jobs.description AS `Jobs__description`, Jobs.detail AS `Jobs__detail`, Jobs.business_skill AS `Jobs__business_skill`, Jobs.knowledge AS `Jobs__knowledge`, Jobs.location AS `Jobs__location`, Jobs.activity AS `Jobs__activity`, Jobs.academic_degree_doctor AS `Jobs__academic_degree_doctor`, Jobs.academic_degree_master AS `Jobs__academic_degree_master`, Jobs.academic_degree_professional AS `Jobs__academic_degree_professional`, Jobs.academic_degree_bachelor AS `Jobs__academic_degree_bachelor`, Jobs.salary_statistic_group AS `Jobs__salary_statistic_group`, Jobs.salary_range_first_year AS `Jobs__salary_range_first_year`, Jobs.salary_range_average AS `Jobs__salary_range_average`, Jobs.salary_range_remarks AS `Jobs__salary_range_remarks`, Jobs.restriction AS `Jobs__restriction`, Jobs.estimated_total_workers AS `Jobs__estimated_total_workers`, Jobs.remarks AS `Jobs__remarks`, Jobs.url AS `Jobs__url`, Jobs.seo_description AS `Jobs__seo_description`, Jobs.seo_keywords AS `Jobs__seo_keywords`, Jobs.sort_order AS `Jobs__sort_order`, Jobs.publish_status AS `Jobs__publish_status`, Jobs.version AS `Jobs__version`, Jobs.created_by AS `Jobs__created_by`, Jobs.created AS `Jobs__created`, Jobs.modified AS `Jobs__modified`, Jobs.deleted AS `Jobs__deleted`, Page 2/4 JobCategories.id AS `JobCategories__id`, JobCategories.name AS `JobCategories__name`, JobCategories.sort_order AS `JobCategories__sort_order`, JobCategories.created_by AS `JobCategories__created_by`, JobCategories.created AS `JobCategories__created`, JobCategories.modified AS `JobCategories__modified`, JobCategories.deleted AS `JobCategories__deleted`, JobTypes.id AS `JobTypes__id`, JobTypes.name AS `JobTypes__name`, JobTypes.job_category_id AS `JobTypes__job_category_id`, JobTypes.sort_order AS `JobTypes__sort_order`, JobTypes.created_by AS `JobTypes__created_by`, JobTypes.created AS `JobTypes__created`, JobTypes.modified AS `JobTypes__modified`, JobTypes.deleted AS `JobTypes__deleted` FROM jobs Jobs LEFT JOIN jobs_personalities JobsPersonalities ON Jobs.id = (JobsPersonalities.job_id) LEFT JOIN personalities Personalities ON (Personalities.id = (JobsPersonalities.personality_id) AND (Personalities.deleted) IS NULL) LEFT JOIN jobs_practical_skills JobsPracticalSkills ON Jobs.id = (JobsPracticalSkills.job_id) LEFT JOIN practical_skills PracticalSkills ON (PracticalSkills.id = (JobsPracticalSkills.practical_skill_id) AND (PracticalSkills.deleted) IS NULL) LEFT JOIN jobs_basic_abilities JobsBasicAbilities ON Jobs.id = (JobsBasicAbilities.job_id) LEFT JOIN basic_abilities BasicAbilities ON (BasicAbilities.id = (JobsBasicAbilities.basic_ability_id) AND (BasicAbilities.deleted) IS NULL) LEFT JOIN jobs_tools JobsTools ON Jobs.id = (JobsTools.job_id) LEFT JOIN affiliates Tools ON (Tools.type = 1 AND Tools.id = (JobsTools.affiliate_id) AND (Tools.deleted) IS NULL) LEFT JOIN jobs_career_paths JobsCareerPaths ON Jobs.id = (JobsCareerPaths.job_id) LEFT JOIN affiliates CareerPaths ON (CareerPaths.type = 3 AND CareerPaths.id = (JobsCareerPaths.affiliate_id) AND (CareerPaths.deleted) IS NULL) LEFT JOIN jobs_rec_qualifications JobsRecQualifications ON Jobs.id = (JobsRecQualifications.job_id) LEFT JOIN affiliates RecQualifications ON (RecQualifications.type = 2 AND RecQualifications.id = (JobsRecQualifications.affiliate_id) Page 3/4 AND (RecQualifications.deleted) IS NULL) LEFT JOIN jobs_req_qualifications JobsReqQualifications ON Jobs.id = (JobsReqQualifications.job_id) LEFT JOIN affiliates ReqQualifications ON (ReqQualifications.type = 2 AND ReqQualifications.id = (JobsReqQualifications.affiliate_id) AND (ReqQualifications.deleted) IS NULL) INNER JOIN job_categories JobCategories ON (JobCategories.id = (Jobs.job_category_id) AND (JobCategories.deleted) IS NULL) INNER JOIN job_types JobTypes ON (JobTypes.id = (Jobs.job_type_id) AND (JobTypes.deleted) IS NULL) WHERE ((JobCategories.name LIKE '%キャビンアテンダント%' OR JobTypes.name LIKE '%キャビンアテンダント%' OR Jobs.name LIKE '%キャビンアテンダント%' OR Jobs.description LIKE '%キャビンアテンダント%' OR Jobs.detail LIKE '%キャビンアテンダント%' OR Jobs.business_skill LIKE '%キャビンアテンダント%' OR Jobs.knowledge LIKE '%キャビンアテンダント%' OR Jobs.location LIKE '%キャビンアテンダント%' OR Jobs.activity LIKE '%キャビンアテンダント%' OR Jobs.salary_statistic_group LIKE '%キャビンアテンダント%' OR Jobs.salary_range_remarks LIKE '%キャビンアテンダント%' OR Jobs.restriction LIKE '%キャビンアテンダント%' OR Jobs.remarks LIKE '%キャビンアテンダント%' OR Personalities.name LIKE '%キャビンアテンダント%' OR PracticalSkills.name LIKE '%キャビンアテンダント%' OR BasicAbilities.name LIKE '%キャビンアテンダント%' OR Tools.name LIKE '%キャビンアテンダント%' OR CareerPaths.name LIKE '%キャビンアテンダント%' OR RecQualifications.name LIKE '%キャビンアテンダント%' OR ReqQualifications.name LIKE '%キャビンアテンダント%') AND publish_status = 1 AND (Jobs.deleted) IS NULL) GROUP BY Jobs.id ORDER BY Jobs.sort_order desc, Jobs.id DESC LIMIT 50 OFFSET 0 1. Use the keyword EXPLAIN e.g (EXPLAIN SELECT Jobs.id AS `Jobs__id`, Jobs.name AS `Jobs__name`, Jobs.media_id AS `Jobs__media_id` ...) which will show the table that is adding time to the total query time. 2. Introduce INDEXING to the query/table especially on the keys that are used for LEFT JOIN and INNER JOIN e.g. ( LEFT JOIN jobs_tools JobsTools ON Jobs.id = (JobsTools.job_id) ). Add the index through the query like so (ALTER TABLE job_tools INDEX(job_tools.id) ). This will reduced the query time substanstially. 3. Avoid using WILDCARDS such as e.g ( Jobs.remarks LIKE '%キャビンアテンダント%' ..) instead use FULL TEXT SEARCH (FTS) e.g (ADD FULLTEXT (Jobs.remarks, PracticalSKills.name, CareerPaths.name ..) ) 4.
sql-improvement's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.