我有以下设计表
car (id char(8) NOT NULL, make char(10) NOT NULL)
with NONCLUSTERED INDEX i0 ON car(make)
~80k rows of which ~2k are makes with code I need
carmake (make char(10) NOT NULL, code int NOT NULL)
with NONCLUSTERED INDEX i1 ON carmake(make)
~2k rows of which 2 have the code I want
所以我想要所有来自汽车的汽车都有carmake.code = 123
如果我这样做......我会得到下面的详细计划
select id FROM car c JOIN carmake m ON c.make = m.make where m.code = 123
请注意,它会扫描大表 - urgh!
如果我执行其中任何一项......计划显示它使用i0索引
select id from car where code ='make1' OR code ='make2'
select id from car where code in('make1','make2')
只要您加入make表以根据代码派生品牌,查询计划就会开始创建重新格式化的工作表,然后表格扫描大表。
我无法弄清楚原因。 sybase文档指出,当要加入的表之间没有合适的密钥时,会重新格式化。在这种情况下,两个表都有make char(10)索引。我还尝试在代码上添加一个索引,这样make不会扫描表,但这仍然会导致初始重新格式化。我怀疑重新格式化导致无法使用汽车索引 - 可能是因为类型冲突和implcit转换?但为什么格式化首先发生?
计划重新格式化然后进行表扫描: -
QUERY PLAN FOR STATEMENT 1 (at line 1).
Executed in parallel by coordinating process and 3 worker processes.
STEP 1
The type of query is INSERT.
The update mode is direct.
Executed by coordinating process.
Worktable1 created for REFORMATTING.
FROM TABLE
make
m
Nested iteration.
Table Scan.
Forward scan.
Positioning at start of table.
Using I/O Size 16 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.
TO TABLE
Worktable1.
STEP 2
The type of query is SELECT.
Executed in parallel by coordinating process and 3 worker processes.
FROM TABLE
car
c
Nested iteration.
Table Scan.
Forward scan.
Positioning at start of table.
Executed in parallel with a 3-way hash scan.
Using I/O Size 16 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.
FROM TABLE
Worktable1.
Nested iteration.
Using Clustered Index.
Forward scan.
Positioning by key.
Using I/O Size 2 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.
Parallel network buffer merge.
The sort for Worktable1 is done in Serial
答案 0 :(得分:0)
谢谢, 戈帕尔