这样的查询大家怎么处理(或者说说大家的库怎么设计的?)顶着有分

wang520d 2008-06-27 02:06:26
客户信息表
gid tel1 tel2 tel3
20081234 15910600407 0104781050 15847323223
20081235 15910600403 0104781051 15847323227
。。。。。
百万计的数据。。。。。。。。。。

得到结果:根据三个电话号码字段取得gid
比如输入:15910600407或者0104781050或者15847323223中的任何一个都能得到20081234


我做呼叫中心 当用户电话打进来 系统要根据这个电话号码去判断客户是不是存在
请高人赐教好的处理办法?
...全文
164 21 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
wang520d 2008-07-01
  • 打赏
  • 举报
回复
非常感谢16楼的回复。。。。很详细很有帮助
happysophie 2008-06-30
  • 打赏
  • 举报
回复
学习了。
yagebu1983 2008-06-28
  • 打赏
  • 举报
回复
16楼说的真详细!!!
yagebu1983 2008-06-28
  • 打赏
  • 举报
回复
百万数据查询用索引吧!!
Navymk 2008-06-28
  • 打赏
  • 举报
回复
mark
  • 打赏
  • 举报
回复
楼主,昨天回去想了想你的问题,也想办法做了一些测试,当然和你的环境和引用可能不一样。刚把测试做完,恰好看到你的帖子。下面是我的测试结果:
----向数据库中插入100万条数据

if not object_id('tb') is null
drop table tb
Go
Create table tb([gid] int,[tel1] nvarchar(11),[tel2] nvarchar(11),[tel3] nvarchar(11))
Insert tb
select 20081234,15910600407,N'0104781050',15847323223 union all
select 20081235,15910600403,N'0104781051',15847323227
Go
Select * from tb

declare @i int,@tel1 char(11),@tel2 char(11),@tel3 char(11),@id bigint
select @i=1,@tel1='15910600407',@tel2='0104781051',@tel3='15847323227'
,@id=20081235
while @i<100000
begin
set @tel1=left(@tel1,4)+cast(cast(right(@tel1,7) as bigint)+@i as char(6))
set @tel2=left(@tel2,4)+cast(cast(right(@tel2,7) as bigint)+@i as char(6))
set @tel3=left(@tel3,4)+cast(cast(right(@tel3,7) as bigint)+@i as char(6))
set @id=@id+@i
insert into tb
values(@id,@tel1,@tel2,@tel3)
set @i=@i+1
end

第一次测试:没有建立任何索引
select gid from tb where tel1=@tel or tel2=@tel or tel3=@tel 需要时间480ms

select gid from tb where tel1=@tel union select gid from tb where tel2=@tel
union select gid from tb where tel3=@tel 需要时间700ms

把两个分别做成存储过程

第一个sql做成存储过程 需要时间480ms
第二个sql做成存储过程 需要时间690ms

第二次测试:在tel1、tel2、tel3上建立联合索引
1、查询时不指定索引
1)select gid from tb where tel1=@tel or tel2=@tel or tel3=@tel 需要时间420ms
2)select gid from tb where tel1=@tel union select gid from tb where tel2=@tel
union select gid from tb where tel3=@tel 需要时间360ms
把两个分别做成存储过程

第一个sql做成存储过程 需要时间420ms
第二个sql做成存储过程 需要时间350ms
2、查询时指定索引
1)select gid from tb(index(i_tb)) where tel1=@tel or tel2=@tel or tel3=@tel 需要时间420ms
2)select gid from tb (index(i_tb)) where tel1=@tel
union
select gid from tb (index(i_tb)) where tel2=@tel
union
select gid from tb (index(i_tb)) where tel3=@tel 需要时间360ms
把两个分别做成存储过程

第一个sql做成存储过程 需要时间420ms
第二个sql做成存储过程 需要时间350ms
第三次测试: 在tel1,tel2,tel3上分别建立索引
create index i_tel1 on tb(tel1)
create index i_tel2 on tb(tel2)
create index i_tel3 on tb(tel3)
1、查询时不指定索引
1) select gid from tb where tel1=@tel or tel2=@tel or tel3=@tel 当页面在内存中,需要时间0ms,不在是需要10ms

2) select gid from tb where tel1=@tel
union
select gid from tb where tel2=@tel
union
select gid from tb where tel3=@tel 当页面在内存中,需要时间0ms,不在是需要10ms

2、查询时指定索引
1)select gid from tb(index(i_tel1,i_tel2,i_tel3)) where tel1=@tel or tel2=@tel or tel3=@tel 需要时间:16000-22000
2)select gid from tb (index(i_tel1)) where tel1=@tel
union
select gid from tb (index(i_tel2)) where tel2=@tel
union
select gid from tb (index(i_tel3)) where tel3=@tel 当页面在内存中,需要时间0ms,不在是需要10ms
2、
把两个分别做成存储过程

第一个sql做成存储过程 当页面在内存中,需要时间0ms,不在是需要10ms
第二个sql做成存储过程 当页面在内存中,需要时间0ms,不在是需要10ms
第四次测试
在tel1上建立聚集索引,在tel2,tel3上建立普通索引
时间和第三次测试时间差不多




  • 打赏
  • 举报
回复
百万级不算什么,只要合理利用索引、合理规划SQL内存与自带的优化策略,很容易搞定的。
如果你用SQL2005,那就更强了!
莫名3 2008-06-27
  • 打赏
  • 举报
回复
也是查询啊 上次我搞个查询 写错个字符 搞了半天就是不对啊 快郁闷死了啊
帮你顶啊
green1202 2008-06-27
  • 打赏
  • 举报
回复
帮顶
tlj8759 2008-06-27
  • 打赏
  • 举报
回复
一對多
建立全文索引是最快的`
mobin4211 2008-06-27
  • 打赏
  • 举报
回复
顶一下,mark
zkcq2004 2008-06-27
  • 打赏
  • 举报
回复
帮顶........................
amandag 2008-06-27
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 wzy_love_sly 的回复:]
多列or的查询没办法快
[/Quote]
hztltgg 2008-06-27
  • 打赏
  • 举报
回复
其实这表有点不符合范式的吧,一对多,建个索引是不是更好些?对用户管理的系统来说,把手机和固定电话放一起不太好,对呼叫中心来说是无所谓的吧
hubblebubblepig 2008-06-27
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 cftea 的回复:]
tel gid
15910600407 20081234
0104781050 20081234
15847323223 20081234
15910600403 20081235
0104781051 20081235
15847323227 20081235

对 tel 建聚集索引,几百万个号码不成问题。
[/Quote]
这种应该可以 把每个用户的三个号码都做为一条单独的记录
syc958 2008-06-27
  • 打赏
  • 举报
回复
全文索引会好一点!
wzy_love_sly 2008-06-27
  • 打赏
  • 举报
回复
select distinct gid from tb where tel in('15910600407','0104781050','15847323223')
wzy_love_sly 2008-06-27
  • 打赏
  • 举报
回复
只能改2列

gid  tel

select * from tb where tel in('15910600407','0104781050','15847323223')



多列or的查询没办法快
cftea 2008-06-27
  • 打赏
  • 举报
回复
tel gid
15910600407 20081234
0104781050 20081234
15847323223 20081234
15910600403 20081235
0104781051 20081235
15847323227 20081235

对 tel 建聚集索引,几百万个号码不成问题。
netwar 2008-06-27
  • 打赏
  • 举报
回复
三个一起or查询啊
select * from 表名 where (tel1=@param or tel2=@param or tel3=@param)
加载更多回复(1)

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧