惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
CXSECURITY Database RSS Feed - CXSecurity.com
Stack Overflow Blog
Stack Overflow Blog
月光博客
月光博客
T
Threat Research - Cisco Blogs
小众软件
小众软件
有赞技术团队
有赞技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
Apple Machine Learning Research
Apple Machine Learning Research
C
Cyber Attacks, Cyber Crime and Cyber Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Tailwind CSS Blog
Cisco Talos Blog
Cisco Talos Blog
V
V2EX
博客园 - 【当耐特】
C
Cybersecurity and Infrastructure Security Agency CISA
Hugging Face - Blog
Hugging Face - Blog
The Cloudflare Blog
The Last Watchdog
The Last Watchdog
Simon Willison's Weblog
Simon Willison's Weblog
T
Threatpost
S
Secure Thoughts
O
OpenAI News
P
Proofpoint News Feed
S
SegmentFault 最新的问题
Forbes - Security
Forbes - Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Application and Cybersecurity Blog
Application and Cybersecurity Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
宝玉的分享
宝玉的分享
Scott Helme
Scott Helme
T
Tenable Blog
A
Arctic Wolf
L
LINUX DO - 热门话题
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V
Visual Studio Blog
Hacker News: Ask HN
Hacker News: Ask HN
Hacker News - Newest:
Hacker News - Newest: "LLM"
腾讯CDC
博客园 - Franky
WordPress大学
WordPress大学
Know Your Adversary
Know Your Adversary
博客园_首页
雷峰网
雷峰网
IT之家
IT之家
PCI Perspectives
PCI Perspectives
L
LINUX DO - 最新话题
H
Heimdal Security Blog

博客园 - Enhydraboy

[ZT]MSN Messenger的口令获取源代码, MSNMessenger的口令是经过DPAPI加密后保存在注册表中 ADO Connection Strings[转贴] 农民造“飞碟”后记 Tomcat's Thread Pool Source(BT) - Enhydraboy 使用 jakata DBCP package 作 DB Connection pooling[ZT] msnlib中的MimeMessage.parse代码需要修改 我的MSN机器人终于有了自己的头像 Field6的类型说明 MSN协议中关于Send DP的研究 搞懂了MSN协议中的client id是怎么得到的 Java正则表达式详解[转载] MSN P2P资料转载 MSN协议中的msnobj浅析 MSNP10中修改自己的FRIENDLY NAME改成了RPR命令 msp10协议中的SYN好像发生了变化 准备让MSN机器人可以显示头像 jMSN开发指南 我自己的msn机器人诞生了 中国足球进步了
数据类型的不匹配可能会导致索引失效
Enhydraboy · 2004-08-25 · via 博客园 - Enhydraboy

       Sybase和SQL Server在这一点上有所不同,如果条件比较中的数据类型不匹配的话,可能会引起索引失效,导致潜在的Performance问题。
       简单说明如下:

插入一些数据后,我们可以测试如下:
1> set showplan on
2> go
1> declare @var_int int
2> select @var_int=2
3> select * from Test where c1=@var_int
4> go

QUERY PLAN FOR STATEMENT 1 (at line 1).


    STEP 1
        The type of query is DECLARE.


QUERY PLAN FOR STATEMENT 2 (at line 2).


    STEP 1
        The type of query is SELECT.


QUERY PLAN FOR STATEMENT 3 (at line 3).


    STEP 1
        The type of query is SELECT.

        FROM TABLE
            Test
        Nested iteration.
        Using Clustered Index.
        Index : PK_Test
        Forward scan.
        Positioning by key.
        Keys are:
            c1  ASC
        Using I/O Size 2 Kbytes for data pages.
        With LRU Buffer Replacement Strategy for data pages.

(1 row affected)
 c1          c2                       c3
 ----------- ------------------------ --------------------
           2                   129.14 Hellen

(1 row affected)
我们看到,sybase的执行计划会使用clustered index来读取数据。

下面,采用money类型来进行测试
1> declare @var_money money
2> select @var_money=2
3> select * from Test where c1=@var_money
4> go

QUERY PLAN FOR STATEMENT 1 (at line 1).


    STEP 1
        The type of query is DECLARE.


QUERY PLAN FOR STATEMENT 2 (at line 2).


    STEP 1
        The type of query is SELECT.


QUERY PLAN FOR STATEMENT 3 (at line 3).


    STEP 1
        The type of query is SELECT.

        FROM TABLE
            Test
        Nested iteration.
        Table Scan.
        Forward scan.
        Positioning at start of table.
        Using I/O Size 2 Kbytes for data pages.
        With LRU Buffer Replacement Strategy for data pages.

(1 row affected)
 c1          c2                       c3
 ----------- ------------------------ --------------------
           2                   129.14 Hellen

(1 row affected)

我们可以看到,sybase没有采用索引,而是采用了全表扫描。

实际上,Sybase并不是类型不一致就一定不会使用索引,而是有一个匹配原则,原则上是只要索引列的类型优先级高于搜索条件的数据类型,就会使用索引。
这个优先级,可以通过查询系统表master.dbo.systypes.
1> select hierarchy,name from master.dbo.systypes
2> order by 1
3> go
 hierarchy name
 --------- ------------------------------
         1 floatn
         2 float
         3 datetimn
         4 datetime
         5 real
         6 numericn
         7 numeric
         8 decimaln
         9 decimal
        10 moneyn
        11 money
        12 smallmoney
        13 smalldatetime
        14 intn
        15 int
        16 smallint
        17 tinyint
        18 bit
        19 univarchar
        20 unichar
        22 sysname
        22 varchar
        22 nvarchar
        23 char
        23 nchar
        24 timestamp
        24 varbinary
        25 binary
        26 text
        27 image
        99 extended type