高分求海量数据简单快速查询
我有一个数据表 里面有一个f_title 字段 为nvarchar 200
数据大概1500万条
现在想对该字段进行查询
比如查询 ”江苏 科技“则显示同时包含江苏 与 科技 2个词语的内容select top 100 * from t_magdetail
where
charindex('江苏',f_title)>0
and
charindex('科技',f_title)>0
order by f_magyear desc其中 f_magyear 是聚焦索引现在 发现查询速度 较慢
请教 该如何优化或者是否可以用其他的SQL实现?
如果 同时查询3个词语 应该如何快速实现?比如说 同时在f_title 出现 包括 江苏 南京 科技 3个词语的结果?
感谢楼下对小弟的指导!

解决方案 »

  1.   

    select   top   100   *   
    from   t_magdetail 
    where f_title like '%江苏%科技%'
    order   by   f_magyear   desc 
      

  2.   

    select   top   100   *   
    from   t_magdetail 
    where PATINDEX('%江苏%科技%', f_title)>0
    order   by   f_magyear   desc 
      

  3.   

    select   top   100   *   
    from   t_magdetail 
    where f_title like '%江苏%科技%'
    order   by   f_magyear   desc 

    select   top   100   *   from   t_magdetail 
    where 
    charindex('江苏',f_title)> 0 
    and 
    charindex('科技',f_title)> 0 
    order   by   f_magyear   desc 
    要慢20秒左右
    总时间需要100秒
    单查1个词语大概10秒左右继续寻求高速查询方法
    等……
      

  4.   

    charindex 和 patindex 很可能造成索引无效,扫全表类似查询意见用全文索引
      

  5.   

    select   top   100   *   
    from   t_magdetail 
    where PATINDEX('%江苏%科技%', f_title)>0
    order   by   f_magyear   desc 
    这样更慢了 大概需要300秒以上时间
      

  6.   

    比如查询   ”江苏   科技“则显示同时包含江苏   与   科技   2个词语的内容 select   top   100   *   from   t_magdetail 
    where 
    charindex('江苏',f_title)> 0 
    and 
    charindex('科技',f_title)> 0 
    order   by   f_magyear   desc 只能这样吧.
      

  7.   

    select   top   100   *   
    from   t_magdetail 
    where f_title like '%江苏%科技%'
    order   by   f_magyear   desc 如果这样,
    那科技在前,江苏在后的就查不出来.
      

  8.   

    全文索引 的话需要耗费大量服务器资源
    现在改数据库就1个表 里面4个字段
    包括3个INT和1个nvarchar 
    如果单检索一个词语 的话 很快 大概10秒内如果这样的话 外部搜索的话只能 检索一个词语或者完全匹配了如果能够支持2个词语 分词 搜索那对于 检索用户而言体验性会更好继续寻求帮助!
      

  9.   

    select       top       100       *       from       t_magdetail   
    where   
    charindex('江苏',f_title)>   0   
    and   
    charindex('科技',f_title)>   0   
    order       by       f_magyear       desc  
    时间 100秒
    select       top       100       *       from       t_magdetail   
    where   
    charindex('江苏',f_title)>   0   
     order       by       f_magyear       desc  
    时间10秒
    数据库大概1500万条记录郁闷中……
    等待中……
      

  10.   

    查询字段有没有加索引?sqlserver对千万以上数量集的数据处理能力明显下降,最好分区存放,用逻辑视图访问,或者数据转储
      

  11.   

    不建索引又要加速,好比不给米又要做饭
    那些字符处理函数跟like 的左+右匹配没有什么区别,不建全文索引,你就在这慢慢郁闷,慢慢等待,慢慢想吧
      

  12.   

    全文索引   的话需要耗费大量服务器资源 
    现在改数据库就1个表   里面4个字段 
    包括3个INT和1个nvarchar   
    如果单检索一个词语   的话   很快   大概10秒内 如果这样的话   外部搜索的话只能   检索一个词语或者完全匹配了 如果能够支持2个词语   分词   搜索那对于   检索用户而言体验性会更好 继续寻求帮助!
    --------------------------------
    如果不用全文索引那必须想办法缩小查询范围,比如在where后多加一个检索条件,并且该列的索引是有效的不然只能1500万数据扫全表10秒只是一个用户的速度,如果有N个用户同时查询,那第一个用户得到数据的时间是10秒,第2个可能20秒,第2个可能30秒以上,以此类推。最后很可能造成表被死锁。
      

  13.   


    --试试
    select   top   100   *   from   t_magdetail 
    where 
    charindex('江苏',f_title)> 0 
    and f_magyear in (
    select magyear from t_magdetail 
    where 
    charindex('科技',f_title)> 0 
    )
    order   by   f_magyear   desc