多表查詢新增索引

2021-09-20 18:30:53 字數 1571 閱讀 4661

共有t_member(成員表)t_organization(單位表)t_member_t_organization(成員單位對映表)

select 語句如下

select tm.id,tm.name,birth,

case ***

when '1' then '男'

when '2' then '女'

else '其他' end as ***,

is_admin as isadmin,

username,password,

duty,qualification,political,email,

tor.name as organization,

is_manager as ismanager,

level,tm.performance,tm.dues,area,company,

job_title as jobtitle,

id_number as idnumber,telephone,qq,photo,grade,item,

grade_date as gradedate,

grade_num as gradenum,

instructed_date as instructeddate,

instructed_num as instructednum,

instructed_item as instructeditem,

managed_date as manageddate,

managed_num as managednum,

managed_item as manageditem,

examed_date as exameddate,

examed_num as examednum,

examed_item as exameditem,

is_judge as isjudge,

judge_number as judgenumber,

judge_date as judgedate,

is_coach as iscoach,

coach_date as coachdate,

coach_number as coachnumber,

is_instructor as isinstructor,

instructor_date as instructordate,

instructor_number as instructornumber,

experience,

activity,tm.status

from t_member tm

left join t_member_organization tmo on tm.id = tmo.member_id

left join t_organization tor on tmo.organization_id = tor.id

人員表中共有5000條資料,此時如果不建立索引進行查詢的話

然後我們試試在對映表上加上索引後

檢視下這時候的資料庫查詢速度

僅僅有0.1秒~ 

這優化效果不錯吧··

Hibernate 多表查詢 新增 刪除

有這麼兩個表 user和role,乙個userid可能對應多個roleid,它倆之間通過userrole連線 查詢方法 override public listqueryroleallbyuserid long userid return list 可以倒著這麼想 最後我是要得到role的,那麼和r...

多表查詢 多表查詢 多表查詢

查詢語法 select 列表名稱 from 表明列表 where 笛卡爾積 有兩個集合a,b,取這兩個集合的所有組成情況 要完成多表查詢,需要消除無用的資料 多表查詢分類 1 內連線查詢 1 隱式內連線 使用where消除無用的資料 例子 select t1.name,t1.gender,t2.na...

mysql 多表查詢or MySQL 多表查詢

前期準備 建表create table dep id int,name varchar 20 create table emp id int primary key auto increment,name varchar 20 enum male female not null default ma...