注:这两个查询条件,都是有索引的
请教高手。
在线等待中。。。。。
14 个解决方案
#1
SQL语句是什么,索引情况如何
#2
sql语句很简单:
SELECT guest.id,
vip_main.card_face,
guest.if_actual,
guest.name,
guest.vip_type,
guest.id_type,
guest.id_card,
guest.telephone,
guest.mobile,
guest.fax,
guest.email,
guest.postcode,
guest.sex,
guest.married,
guest.educate_degree,
guest.job,
guest.prefix,
guest.birthday,
guest.area,
guest.id_address,
guest.address,
guest.devotion,
guest.contribute,
guest.satisfaction,
guest.habit_day,
guest.recdate,
guest.manager,
guest.vip_state,
guest.use_organ,
guest.organ,
guest.make_organ,
guest.guest_type,
guest.consume_type,
guest.phaseal ,
guest.remark,
0.01 as sum_integral,
0.01 as available_integarl,
0.01 as sum_price,
0.01 as sum_bala,
0.01 as sum_token,
0.01 as token_bala
FROM guest,
vip_main
WHERE ( guest.id = vip_main.guest_id ) AND
( vip_main.card_primal = 1 ) AND
( vip_main.card_state <>2 ) AND
( guest.id like '91700100%' OR
vip_main.card_face like '91700100%'
)
在guest表中有主键索引,id为主键,在vip_main表中card_face、card_id和主键索引,card_id为主键
SELECT guest.id,
vip_main.card_face,
guest.if_actual,
guest.name,
guest.vip_type,
guest.id_type,
guest.id_card,
guest.telephone,
guest.mobile,
guest.fax,
guest.email,
guest.postcode,
guest.sex,
guest.married,
guest.educate_degree,
guest.job,
guest.prefix,
guest.birthday,
guest.area,
guest.id_address,
guest.address,
guest.devotion,
guest.contribute,
guest.satisfaction,
guest.habit_day,
guest.recdate,
guest.manager,
guest.vip_state,
guest.use_organ,
guest.organ,
guest.make_organ,
guest.guest_type,
guest.consume_type,
guest.phaseal ,
guest.remark,
0.01 as sum_integral,
0.01 as available_integarl,
0.01 as sum_price,
0.01 as sum_bala,
0.01 as sum_token,
0.01 as token_bala
FROM guest,
vip_main
WHERE ( guest.id = vip_main.guest_id ) AND
( vip_main.card_primal = 1 ) AND
( vip_main.card_state <>2 ) AND
( guest.id like '91700100%' OR
vip_main.card_face like '91700100%'
)
在guest表中有主键索引,id为主键,在vip_main表中card_face、card_id和主键索引,card_id为主键
#3
vip_main上增加guest_id、card_face复合索引
card_primal、card_state有多少种值
card_primal、card_state有多少种值
#4
create index xx on vip_main(guest_id,card_primal,card_state,card_face)
create index xx1 on guest(card_state)
create index xx1 on guest(card_state)
#5
另外你的语句应该是错误的!
( vip_main.card_state <>2 ) AND
( guest.id like '91700100%' OR
vip_main.card_face like '91700100%'
这个语句应该会报语法错误。
( vip_main.card_state <>2 ) AND
( guest.id like '91700100%' OR
vip_main.card_face like '91700100%'
这个语句应该会报语法错误。
#6
3楼
card_primal:有2个取值、
card_state:有3种取值
card_primal:有2个取值、
card_state:有3种取值
#7
值不多,建立索引效率不高,
vip_main上增加guest_id、card_face复合索引
vip_main上增加guest_id、card_face复合索引
#8
在VIP_main表上建了guest_id和card_face都索引,还是慢得很,不过要快一点
#9
建议将OR->UNION ALL
....
WHERE ( guest.id = vip_main.guest_id ) AND
( vip_main.card_primal = 1 ) AND
( vip_main.card_state <>2 ) AND
guest.id like '91700100%'
UNION ALL
....
WHERE ( guest.id = vip_main.guest_id ) AND
( vip_main.card_primal = 1 ) AND
( vip_main.card_state <>2 ) AND
vip_main.card_face like '91700100%'
....
WHERE ( guest.id = vip_main.guest_id ) AND
( vip_main.card_primal = 1 ) AND
( vip_main.card_state <>2 ) AND
guest.id like '91700100%'
UNION ALL
....
WHERE ( guest.id = vip_main.guest_id ) AND
( vip_main.card_primal = 1 ) AND
( vip_main.card_state <>2 ) AND
vip_main.card_face like '91700100%'
#10
9楼,
这个办法有点意思,
如果没有其它更好的办法,就只有这样整了
这个办法有点意思,
如果没有其它更好的办法,就只有这样整了
#11
#12
不懂啊,我也想了解这个问题
#13
#14
像like这种的是全表扫描的,而且用不了索引。。你可以用explain来观察一下。
#1
SQL语句是什么,索引情况如何
#2
sql语句很简单:
SELECT guest.id,
vip_main.card_face,
guest.if_actual,
guest.name,
guest.vip_type,
guest.id_type,
guest.id_card,
guest.telephone,
guest.mobile,
guest.fax,
guest.email,
guest.postcode,
guest.sex,
guest.married,
guest.educate_degree,
guest.job,
guest.prefix,
guest.birthday,
guest.area,
guest.id_address,
guest.address,
guest.devotion,
guest.contribute,
guest.satisfaction,
guest.habit_day,
guest.recdate,
guest.manager,
guest.vip_state,
guest.use_organ,
guest.organ,
guest.make_organ,
guest.guest_type,
guest.consume_type,
guest.phaseal ,
guest.remark,
0.01 as sum_integral,
0.01 as available_integarl,
0.01 as sum_price,
0.01 as sum_bala,
0.01 as sum_token,
0.01 as token_bala
FROM guest,
vip_main
WHERE ( guest.id = vip_main.guest_id ) AND
( vip_main.card_primal = 1 ) AND
( vip_main.card_state <>2 ) AND
( guest.id like '91700100%' OR
vip_main.card_face like '91700100%'
)
在guest表中有主键索引,id为主键,在vip_main表中card_face、card_id和主键索引,card_id为主键
SELECT guest.id,
vip_main.card_face,
guest.if_actual,
guest.name,
guest.vip_type,
guest.id_type,
guest.id_card,
guest.telephone,
guest.mobile,
guest.fax,
guest.email,
guest.postcode,
guest.sex,
guest.married,
guest.educate_degree,
guest.job,
guest.prefix,
guest.birthday,
guest.area,
guest.id_address,
guest.address,
guest.devotion,
guest.contribute,
guest.satisfaction,
guest.habit_day,
guest.recdate,
guest.manager,
guest.vip_state,
guest.use_organ,
guest.organ,
guest.make_organ,
guest.guest_type,
guest.consume_type,
guest.phaseal ,
guest.remark,
0.01 as sum_integral,
0.01 as available_integarl,
0.01 as sum_price,
0.01 as sum_bala,
0.01 as sum_token,
0.01 as token_bala
FROM guest,
vip_main
WHERE ( guest.id = vip_main.guest_id ) AND
( vip_main.card_primal = 1 ) AND
( vip_main.card_state <>2 ) AND
( guest.id like '91700100%' OR
vip_main.card_face like '91700100%'
)
在guest表中有主键索引,id为主键,在vip_main表中card_face、card_id和主键索引,card_id为主键
#3
vip_main上增加guest_id、card_face复合索引
card_primal、card_state有多少种值
card_primal、card_state有多少种值
#4
create index xx on vip_main(guest_id,card_primal,card_state,card_face)
create index xx1 on guest(card_state)
create index xx1 on guest(card_state)
#5
另外你的语句应该是错误的!
( vip_main.card_state <>2 ) AND
( guest.id like '91700100%' OR
vip_main.card_face like '91700100%'
这个语句应该会报语法错误。
( vip_main.card_state <>2 ) AND
( guest.id like '91700100%' OR
vip_main.card_face like '91700100%'
这个语句应该会报语法错误。
#6
3楼
card_primal:有2个取值、
card_state:有3种取值
card_primal:有2个取值、
card_state:有3种取值
#7
值不多,建立索引效率不高,
vip_main上增加guest_id、card_face复合索引
vip_main上增加guest_id、card_face复合索引
#8
在VIP_main表上建了guest_id和card_face都索引,还是慢得很,不过要快一点
#9
建议将OR->UNION ALL
....
WHERE ( guest.id = vip_main.guest_id ) AND
( vip_main.card_primal = 1 ) AND
( vip_main.card_state <>2 ) AND
guest.id like '91700100%'
UNION ALL
....
WHERE ( guest.id = vip_main.guest_id ) AND
( vip_main.card_primal = 1 ) AND
( vip_main.card_state <>2 ) AND
vip_main.card_face like '91700100%'
....
WHERE ( guest.id = vip_main.guest_id ) AND
( vip_main.card_primal = 1 ) AND
( vip_main.card_state <>2 ) AND
guest.id like '91700100%'
UNION ALL
....
WHERE ( guest.id = vip_main.guest_id ) AND
( vip_main.card_primal = 1 ) AND
( vip_main.card_state <>2 ) AND
vip_main.card_face like '91700100%'
#10
9楼,
这个办法有点意思,
如果没有其它更好的办法,就只有这样整了
这个办法有点意思,
如果没有其它更好的办法,就只有这样整了
#11
#12
不懂啊,我也想了解这个问题
#13
#14
像like这种的是全表扫描的,而且用不了索引。。你可以用explain来观察一下。