0

私は次の人為的なテーブルを持っています

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 を持つ car のすべての車が必要です

これを行うと...以下の詳細な計画が表示されます

select id FROM car c JOIN carmake m ON c.make = m.make where m.code = 123

テーブルは大きなテーブルをスキャンすることに注意してください-うーん!

これらのいずれかを実行すると...計画は i0 インデックスを使用することを示しています

select id from car where code ='make1' OR code ='make2'  
select id from car where code in('make1','make2')  

コードに基づいて make を導出するために make テーブルに参加するとすぐに、クエリ プランは再フォーマットされた作業テーブルの作成を開始し、続いて大きなテーブルをテーブル スキャンします。

理由がわかりません。sybase のドキュメントには、結合するテーブル間に適切なキーがない場合に再フォーマットが発生すると記載されています。この場合、両方のテーブルに make char(10) インデックスがあります。make がテーブルをスキャンしないように、コードにインデックスを追加しようとしましたが、それでも最初の再フォーマットが行われます。再フォーマットにより、車のインデックスを使用できなくなると思われます-おそらく型の衝突と暗黙の変換が原因でしょうか? しかし、そもそもなぜ書式設定が行われるのでしょうか?

再フォーマットしてからテーブルスキャンを計画する: -

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
4

1 に答える 1