mysql - SQL多表查询速度慢

标签 mysql sql

我有 4 张 table :

bag_of_words(
    ch_id,
    frequency,
    number,w_id
)

clinical_history(
    ch_complete,
    ch_id,p_id
)

patients(
    p_id,
    p_name
)

words(
    w_id,
    w_word
)

我有一个选定单词的列表。我需要从表 w_wordp_namenumberfreqencych_id 中进行选择>.

我有这个查询,但它很慢,我需要它更快

SELECT  
    w_word, 
    p_name, 
    number, 
    frequency, 
    bag_of_words.ch_id
FROM
    bag_of_words
LEFT JOIN 
    words 
ON 
    words.w_id=bag_of_words.w_id
LEFT JOIN 
    clinical_history 
ON 
    bag_of_words.ch_id=clinical_history.ch_id
LEFT JOIN 
    patients 
ON 
    patients.p_id=clinical_history.p_id
WHERE 
    words.w_word IN (',,,,,')

最佳答案

您可以使用 View 来提高查询性能。 (检查:Views)。顺便问一下,你使用索引吗?索引还可以提高性能。

关于mysql - SQL多表查询速度慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17948029/

相关文章:

sql - 什么是全文搜索与 LIKE

c# - 使用 Microsoft.SqlServer.Dac.DacServices 在单用户模式下发布 dacpac

mysql - 使用外键跟踪新关系中的所有权

java - 如何将数据插入同步更新java中的JTable的mysql数据库?

java - 使用 mysql 分割 .csv 文件

mysql - 在日期字段中插入空值的兼容性查询

mysql - SQL - 来自 [剧透 :abcdefgh] to [spoiler]

浏览器跟踪器的 mySQL 查询优化

mysql - Birt:将用户停留时间存储在报告中并访问数据库

mysql - 如何施加固定长度字段