Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2010
    Posts
    4

    Question Unanswered: Query speed and plan question

    Hello,

    I have a query that's running an IN/Subselect that joins three different tables and gets a list of IDs to compare against... the subselect basically looks for records through a join table based on the 3rd table's name, similar to:

    Code:
    ... IN (SELECT id FROM foo, foo_bar, bar 
            WHERE foo.id = foo_bar.foo_id 
                AND bar.id = foo_bar.bar_id 
                AND bar.name = "something") ...
    This is all nested in a fairly complex query, and several of these subselects operate on different tables within the query. The whole thing, on some high-cardinality cases, can take 2.5 seconds to run (clearly something can be done about that).

    So in this example, the cardinality of the bar table is very low, and fairly constant, something on the order of 5-7 records. In an optimization attempt, I reduced the joins in the subselect from 2 to 1 by passing in the ID of the bar with the correct name, which I can easily cache application-side or pre-fetch in a single query. Now it looks like this:

    Code:
    ... IN (SELECT id FROM foo, foo_bar 
             WHERE foo.id = foo_bar.foo_id 
                 AND foo_bar.bar_id = 1) ...
    Crazy thing is, that single optimization reduced the query time significantly, from 2.5-3 seconds down to 40-60ms.

    Does anyone have any kind of explanation for this? Are the inner workings of the IN clause taking the plan for the subselect into account when running, and doing something clever with it? Any insight on the internal mechanisms of IN or subselects in Postgres would be greatly appreciated if anyone knows more.

    Also, are there any better ways you can think of doing such an IN query, using non-subselect means that might be more efficient?

    Thanks in advance, any advice/help understanding this better is greatly appreciated.

  2. #2
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Did you check the execution plans for both statements? What is the difference?

    Are your statistics up-to-date (i.e. do you have auto-vacuum running?)

  3. #3
    Join Date
    Nov 2010
    Posts
    4
    Thanks for the reply - here are some query plans from running the query in both ways.

    First for the original query, the subselect joining all three tables using the third table's name column to select. This one for this specific item is taking about 584ms.

    Code:
    ====================================================================================================================
    Original Query
    ====================================================================================================================
    IN subselect joins to Context table and uses Context name to select
    Time: 584ms
    Subselect: in (select product_items.branch_id  from product_items, branches, contexts  where product_items.branch_id = branches.id  and branches.context_id = contexts.id and contexts.name = 'default')
    ====================================================================================================================
    Nested Loop Left Join  (cost=22235.59..22264.51 rows=2 width=1374)
      ->  Nested Loop Left Join  (cost=22235.59..22262.46 rows=2 width=1279)
            ->  Hash Left Join  (cost=22235.59..22254.30 rows=2 width=1184)
                  Hash Cond: (product_detail_bitemporals_product_items.id = product_details.bitemporal_id)
                  ->  Nested Loop Left Join  (cost=14428.10..14446.73 rows=2 width=269)
                        ->  Nested Loop  (cost=14428.10..14444.67 rows=2 width=174)
                              ->  Unique  (cost=14428.10..14428.11 rows=2 width=4)
                                    ->  Sort  (cost=14428.10..14428.11 rows=2 width=4)
                                          Sort Key: product_items.id
                                          ->  Hash Left Join  (cost=14379.91..14428.09 rows=2 width=4)
                                                Hash Cond: (bitemporals.id = product_details.bitemporal_id)
                                                Filter: ((((product_items.season_bitemporal_id = 0) OR (product_items.season_bitemporal_id IS NULL) OR (product_items.season_bitemporal_id = 109505)) AND (product_details.status_bitemporal_id <> 0) AND (product_details.status_bitemporal_id IS NOT NULL)) OR (product_items.season_bitemporal_id = 0) OR (product_items.season_bitemporal_id IS NULL) OR (product_items.season_bitemporal_id = 109505))
                                                ->  Nested Loop Left Join  (cost=6572.42..6620.51 rows=2 width=12)
                                                      ->  Hash IN Join  (cost=6572.42..6603.94 rows=2 width=12)
                                                            Hash Cond: (product_items.branch_id = public.product_items.branch_id)
                                                            ->  Bitmap Heap Scan on product_items  (cost=4.33..35.80 rows=2 width=16)
                                                                  Recheck Cond: (owner_bitemporal_id = 135911)
                                                                  Filter: ((NOT removed) AND (rev_out IS NULL) AND (effect_in <= '2010-11-29 13:14:55'::timestamp without time zone) AND (effect_out > '2010-11-29 13:14:55'::timestamp without time zone) AND ((color_bitemporal_id = 0) OR (color_bitemporal_id IS NULL)) AND ((size_bitemporal_id = 0) OR (size_bitemporal_id IS NULL)) AND (id > 0))
                                                                  ->  Bitmap Index Scan on index_owner_bitemporal_id_on_product_items  (cost=0.00..4.33 rows=11 width=0)
                                                                        Index Cond: (owner_bitemporal_id = 135911)
                                                            ->  Hash  (cost=6543.32..6543.32 rows=1982 width=8)
                                                                  ->  Hash Join  (cost=6043.15..6543.32 rows=1982 width=8)
                                                                        Hash Cond: (public.product_items.branch_id = public.branches.id)
                                                                        ->  Seq Scan on product_items  (cost=0.00..112.65 rows=3965 width=4)
                                                                        ->  Hash  (cost=4779.88..4779.88 rows=76982 width=4)
                                                                              ->  Hash Join  (cost=1.04..4779.88 rows=76982 width=4)
                                                                                    Hash Cond: (public.branches.context_id = public.contexts.id)
                                                                                    ->  Seq Scan on branches  (cost=0.00..3431.65 rows=153965 width=8)
                                                                                    ->  Hash  (cost=1.02..1.02 rows=1 width=4)
                                                                                          ->  Seq Scan on contexts  (cost=0.00..1.02 rows=1 width=4)
                                                                                                Filter: (name = 'default'::text)
                                                      ->  Index Scan using bitemporals_pkey on bitemporals  (cost=0.00..8.28 rows=1 width=4)
                                                            Index Cond: (bitemporals.id = product_items.product_detail_bitemporal_id)
                                                            Filter: (bitemporals.type = 'ProductDetailBitemporal'::text)
                                                ->  Hash  (cost=7800.81..7800.81 rows=534 width=8)
                                                      ->  Seq Scan on product_details  (cost=7657.30..7800.81 rows=534 width=8)
                                                            Filter: ((NOT removed) AND (rev_out IS NULL) AND (effect_in <= '2010-11-29 13:14:55'::timestamp without time zone) AND (effect_out > '2010-11-29 13:14:55'::timestamp without time zone) AND (hashed subplan))
                                                            SubPlan
                                                              ->  Hash Join  (cost=162.12..7652.90 rows=1758 width=4)
                                                                    Hash Cond: (public.branches.id = public.product_details.branch_id)
                                                                    ->  Hash Join  (cost=1.04..4779.88 rows=76982 width=4)
                                                                          Hash Cond: (public.branches.context_id = public.contexts.id)
                                                                          ->  Seq Scan on branches  (cost=0.00..3431.65 rows=153965 width=8)
                                                                          ->  Hash  (cost=1.02..1.02 rows=1 width=4)
                                                                                ->  Seq Scan on contexts  (cost=0.00..1.02 rows=1 width=4)
                                                                                      Filter: (name = 'default'::text)
                                                                    ->  Hash  (cost=117.15..117.15 rows=3515 width=4)
                                                                          ->  Seq Scan on product_details  (cost=0.00..117.15 rows=3515 width=4)
                              ->  Index Scan using product_items_pkey on product_items  (cost=0.00..8.27 rows=1 width=174)
                                    Index Cond: (product_items.id = product_items.id)
                        ->  Index Scan using bitemporals_pkey on bitemporals product_detail_bitemporals_product_items  (cost=0.00..1.02 rows=1 width=95)
                              Index Cond: (product_detail_bitemporals_product_items.id = product_items.product_detail_bitemporal_id)
                              Filter: (product_detail_bitemporals_product_items.type = 'ProductDetailBitemporal'::text)
                  ->  Hash  (cost=7800.81..7800.81 rows=534 width=915)
                        ->  Seq Scan on product_details  (cost=7657.30..7800.81 rows=534 width=915)
                              Filter: ((NOT removed) AND (rev_out IS NULL) AND (effect_in <= '2010-11-29 13:14:55'::timestamp without time zone) AND (effect_out > '2010-11-29 13:14:55'::timestamp without time zone) AND (hashed subplan))
                              SubPlan
                                ->  Hash Join  (cost=162.12..7652.90 rows=1758 width=4)
                                      Hash Cond: (public.branches.id = public.product_details.branch_id)
                                      ->  Hash Join  (cost=1.04..4779.88 rows=76982 width=4)
                                            Hash Cond: (public.branches.context_id = public.contexts.id)
                                            ->  Seq Scan on branches  (cost=0.00..3431.65 rows=153965 width=8)
                                            ->  Hash  (cost=1.02..1.02 rows=1 width=4)
                                                  ->  Seq Scan on contexts  (cost=0.00..1.02 rows=1 width=4)
                                                        Filter: (name = 'default'::text)
                                      ->  Hash  (cost=117.15..117.15 rows=3515 width=4)
                                            ->  Seq Scan on product_details  (cost=0.00..117.15 rows=3515 width=4)
            ->  Index Scan using bitemporals_pkey on bitemporals status_bitemporals_product_details  (cost=0.00..4.07 rows=1 width=95)
                  Index Cond: (status_bitemporals_product_details.id = product_details.status_bitemporal_id)
                  Filter: (status_bitemporals_product_details.type = 'StatusBitemporal'::text)
      ->  Index Scan using bitemporals_pkey on bitemporals  (cost=0.00..1.02 rows=1 width=95)
            Index Cond: (bitemporals.id = product_items.bitemporal_id)
            Filter: (bitemporals.type = 'ProductItemBitemporal'::text)

    Looks like I'm going to have to do three different posts for these query plans... to be continued.

  4. #4
    Join Date
    Nov 2010
    Posts
    4
    Next for the "Optimized" query - I say "optimized" because there's something funny going on which I'll get to next. In any case, this one runs in about 221ms - here's the plan:

    Code:
    ====================================================================================================================
    "Optimized" Query
    ====================================================================================================================
    IN subselect joins to Context table, but Context table is not used in Subquery criteria
    Time: 221ms
    Subselect: in (select product_details.branch_id  from product_details, branches, contexts  where product_details.branch_id = branches.id  and branches.context_id = 1)
    ====================================================================================================================
    
    Nested Loop Left Join  (cost=26048.13..26077.05 rows=2 width=1374)
      ->  Nested Loop Left Join  (cost=26048.13..26074.99 rows=2 width=1279)
            ->  Hash Left Join  (cost=26048.13..26066.84 rows=2 width=1184)
                  Hash Cond: (product_detail_bitemporals_product_items.id = product_details.bitemporal_id)
                  ->  Nested Loop Left Join  (cost=16337.17..16355.80 rows=2 width=269)
                        ->  Nested Loop  (cost=16337.17..16353.74 rows=2 width=174)
                              ->  Unique  (cost=16337.17..16337.18 rows=2 width=4)
                                    ->  Sort  (cost=16337.17..16337.17 rows=2 width=4)
                                          Sort Key: product_items.id
                                          ->  Nested Loop IN Join  (cost=9715.29..16337.16 rows=2 width=4)
                                                Join Filter: (product_items.branch_id = public.product_items.branch_id)
                                                ->  Hash Left Join  (cost=9715.29..9763.43 rows=2 width=8)
                                                      Hash Cond: (bitemporals.id = product_details.bitemporal_id)
                                                      Filter: ((((product_items.season_bitemporal_id = 0) OR (product_items.season_bitemporal_id IS NULL) OR (product_items.season_bitemporal_id = 109505)) AND (product_details.status_bitemporal_id <> 0) AND (product_details.status_bitemporal_id IS NOT NULL)) OR (product_items.season_bitemporal_id = 0) OR (product_items.season_bitemporal_id IS NULL) OR (product_items.season_bitemporal_id = 109505))
                                                      ->  Nested Loop Left Join  (cost=4.33..52.37 rows=2 width=16)
                                                            ->  Bitmap Heap Scan on product_items  (cost=4.33..35.80 rows=2 width=16)
                                                                  Recheck Cond: (owner_bitemporal_id = 135911)
                                                                  Filter: ((NOT removed) AND (rev_out IS NULL) AND (effect_in <= '2010-11-29 13:14:55'::timestamp without time zone) AND (effect_out > '2010-11-29 13:14:55'::timestamp without time zone) AND ((color_bitemporal_id = 0) OR (color_bitemporal_id IS NULL)) AND ((size_bitemporal_id = 0) OR (size_bitemporal_id IS NULL)) AND (id > 0))
                                                                  ->  Bitmap Index Scan on index_owner_bitemporal_id_on_product_items  (cost=0.00..4.33 rows=11 width=0)
                                                                        Index Cond: (owner_bitemporal_id = 135911)
                                                            ->  Index Scan using bitemporals_pkey on bitemporals  (cost=0.00..8.28 rows=1 width=4)
                                                                  Index Cond: (bitemporals.id = product_items.product_detail_bitemporal_id)
                                                                  Filter: (bitemporals.type = 'ProductDetailBitemporal'::text)
                                                      ->  Hash  (cost=9704.28..9704.28 rows=534 width=8)
                                                            ->  Seq Scan on product_details  (cost=9560.77..9704.28 rows=534 width=8)
                                                                  Filter: ((NOT removed) AND (rev_out IS NULL) AND (effect_in <= '2010-11-29 13:14:55'::timestamp without time zone) AND (effect_out > '2010-11-29 13:14:55'::timestamp without time zone) AND (hashed subplan))
                                                                  SubPlan
                                                                    ->  Nested Loop  (cost=162.11..9543.20 rows=7030 width=4)
                                                                          ->  Hash Join  (cost=161.09..9401.58 rows=3515 width=4)
                                                                                Hash Cond: (public.branches.id = public.product_details.branch_id)
                                                                                ->  Seq Scan on branches  (cost=0.00..3816.56 rows=153965 width=4)
                                                                                      Filter: (context_id = 1)
                                                                                ->  Hash  (cost=117.15..117.15 rows=3515 width=4)
                                                                                      ->  Seq Scan on product_details  (cost=0.00..117.15 rows=3515 width=4)
                                                                          ->  Materialize  (cost=1.02..1.04 rows=2 width=0)
                                                                                ->  Seq Scan on contexts  (cost=0.00..1.02 rows=2 width=0)
                                                ->  Nested Loop  (cost=0.00..14691.77 rows=7930 width=8)
                                                      ->  Nested Loop  (cost=0.00..10568.17 rows=3965 width=8)
                                                            ->  Seq Scan on product_items  (cost=0.00..112.65 rows=3965 width=4)
                                                            ->  Index Scan using branches_pkey on branches  (cost=0.00..2.62 rows=1 width=4)
                                                                  Index Cond: (public.branches.id = public.product_items.branch_id)
                                                                  Filter: (public.branches.context_id = 1)
                                                      ->  Seq Scan on contexts  (cost=0.00..1.02 rows=2 width=0)
                              ->  Index Scan using product_items_pkey on product_items  (cost=0.00..8.27 rows=1 width=174)
                                    Index Cond: (product_items.id = product_items.id)
                        ->  Index Scan using bitemporals_pkey on bitemporals product_detail_bitemporals_product_items  (cost=0.00..1.02 rows=1 width=95)
                              Index Cond: (product_detail_bitemporals_product_items.id = product_items.product_detail_bitemporal_id)
                              Filter: (product_detail_bitemporals_product_items.type = 'ProductDetailBitemporal'::text)
                  ->  Hash  (cost=9704.28..9704.28 rows=534 width=915)
                        ->  Seq Scan on product_details  (cost=9560.77..9704.28 rows=534 width=915)
                              Filter: ((NOT removed) AND (rev_out IS NULL) AND (effect_in <= '2010-11-29 13:14:55'::timestamp without time zone) AND (effect_out > '2010-11-29 13:14:55'::timestamp without time zone) AND (hashed subplan))
                              SubPlan
                                ->  Nested Loop  (cost=162.11..9543.20 rows=7030 width=4)
                                      ->  Hash Join  (cost=161.09..9401.58 rows=3515 width=4)
                                            Hash Cond: (public.branches.id = public.product_details.branch_id)
                                            ->  Seq Scan on branches  (cost=0.00..3816.56 rows=153965 width=4)
                                                  Filter: (context_id = 1)
                                            ->  Hash  (cost=117.15..117.15 rows=3515 width=4)
                                                  ->  Seq Scan on product_details  (cost=0.00..117.15 rows=3515 width=4)
                                      ->  Materialize  (cost=1.02..1.04 rows=2 width=0)
                                            ->  Seq Scan on contexts  (cost=0.00..1.02 rows=2 width=0)
            ->  Index Scan using bitemporals_pkey on bitemporals status_bitemporals_product_details  (cost=0.00..4.07 rows=1 width=95)
                  Index Cond: (status_bitemporals_product_details.id = product_details.status_bitemporal_id)
                  Filter: (status_bitemporals_product_details.type = 'StatusBitemporal'::text)
      ->  Index Scan using bitemporals_pkey on bitemporals  (cost=0.00..1.02 rows=1 width=95)
            Index Cond: (bitemporals.id = product_items.bitemporal_id)
            Filter: (bitemporals.type = 'ProductItemBitemporal'::text)

  5. #5
    Join Date
    Nov 2010
    Posts
    4
    Now for the real question. In the above example, I accidentally left the "contexts" table in the FROM clause of the subselect, even though it was not used in the where clause. Turns out this was lucky, as it seems to be the reason the query sped up so much. Here's the same query with the unused table removed from the FROM clause of the subselects - It takes about 650ms to run, even slower than the original.

    Code:
    ====================================================================================================================
    ID Passed in, Context table not in Join
    ====================================================================================================================
    Plan with ID denormalization and Context table removed from join
    Time: 650ms
    Subselect: in (select product_items.branch_id  from product_items, branches  where product_items.branch_id = branches.id  and branches.context_id  = 1)
    ====================================================================================================================
    Nested Loop Left Join  (cost=26363.56..26392.48 rows=2 width=1374)
      ->  Nested Loop Left Join  (cost=26363.56..26390.42 rows=2 width=1279)
            ->  Hash Left Join  (cost=26363.56..26382.27 rows=2 width=1184)
                  Hash Cond: (product_detail_bitemporals_product_items.id = product_details.bitemporal_id)
                  ->  Nested Loop Left Join  (cost=16652.60..16671.23 rows=2 width=269)
                        ->  Nested Loop  (cost=16652.60..16669.17 rows=2 width=174)
                              ->  Unique  (cost=16652.60..16652.61 rows=2 width=4)
                                    ->  Sort  (cost=16652.60..16652.60 rows=2 width=4)
                                          Sort Key: product_items.id
                                          ->  Hash Left Join  (cost=15908.01..16652.59 rows=2 width=4)
                                                Hash Cond: (bitemporals.id = product_details.bitemporal_id)
                                                Filter: ((((product_items.season_bitemporal_id = 0) OR (product_items.season_bitemporal_id IS NULL) OR (product_items.season_bitemporal_id = 109505)) AND (product_details.status_bitemporal_id <> 0) AND (product_details.status_bitemporal_id IS NOT NULL)) OR (product_items.season_bitemporal_id = 0) OR (product_items.season_bitemporal_id IS NULL) OR (product_items.season_bitemporal_id = 109505))
                                                ->  Nested Loop Left Join  (cost=6347.46..7091.94 rows=2 width=12)
                                                      ->  Nested Loop IN Join  (cost=6347.46..7075.37 rows=2 width=12)
                                                            Join Filter: (public.product_items.branch_id = product_items.branch_id)
                                                            ->  Bitmap Heap Scan on product_items  (cost=4.33..35.80 rows=2 width=16)
                                                                  Recheck Cond: (owner_bitemporal_id = 135911)
                                                                  Filter: ((NOT removed) AND (rev_out IS NULL) AND (effect_in <= '2010-11-29 13:14:55'::timestamp without time zone) AND (effect_out > '2010-11-29 13:14:55'::timestamp without time zone) AND ((color_bitemporal_id = 0) OR (color_bitemporal_id IS NULL)) AND ((size_bitemporal_id = 0) OR (size_bitemporal_id IS NULL)) AND (id > 0))
                                                                  ->  Bitmap Index Scan on index_owner_bitemporal_id_on_product_items  (cost=0.00..4.33 rows=11 width=0)
                                                                        Index Cond: (owner_bitemporal_id = 135911)
                                                            ->  Hash Join  (cost=6343.12..7164.12 rows=3965 width=8)
                                                                  Hash Cond: (public.product_items.branch_id = public.branches.id)
                                                                  ->  Seq Scan on product_items  (cost=0.00..112.65 rows=3965 width=4)
                                                                  ->  Hash  (cost=3816.56..3816.56 rows=153965 width=4)
                                                                        ->  Seq Scan on branches  (cost=0.00..3816.56 rows=153965 width=4)
                                                                              Filter: (context_id = 1)
                                                      ->  Index Scan using bitemporals_pkey on bitemporals  (cost=0.00..8.28 rows=1 width=4)
                                                            Index Cond: (bitemporals.id = product_items.product_detail_bitemporal_id)
                                                            Filter: (bitemporals.type = 'ProductDetailBitemporal'::text)
                                                ->  Hash  (cost=9553.88..9553.88 rows=534 width=8)
                                                      ->  Seq Scan on product_details  (cost=9410.36..9553.88 rows=534 width=8)
                                                            Filter: ((NOT removed) AND (rev_out IS NULL) AND (effect_in <= '2010-11-29 13:14:55'::timestamp without time zone) AND (effect_out > '2010-11-29 13:14:55'::timestamp without time zone) AND (hashed subplan))
                                                            SubPlan
                                                              ->  Hash Join  (cost=161.09..9401.58 rows=3515 width=4)
                                                                    Hash Cond: (public.branches.id = public.product_details.branch_id)
                                                                    ->  Seq Scan on branches  (cost=0.00..3816.56 rows=153965 width=4)
                                                                          Filter: (context_id = 1)
                                                                    ->  Hash  (cost=117.15..117.15 rows=3515 width=4)
                                                                          ->  Seq Scan on product_details  (cost=0.00..117.15 rows=3515 width=4)
                              ->  Index Scan using product_items_pkey on product_items  (cost=0.00..8.27 rows=1 width=174)
                                    Index Cond: (product_items.id = product_items.id)
                        ->  Index Scan using bitemporals_pkey on bitemporals product_detail_bitemporals_product_items  (cost=0.00..1.02 rows=1 width=95)
                              Index Cond: (product_detail_bitemporals_product_items.id = product_items.product_detail_bitemporal_id)
                              Filter: (product_detail_bitemporals_product_items.type = 'ProductDetailBitemporal'::text)
                  ->  Hash  (cost=9704.28..9704.28 rows=534 width=915)
                        ->  Seq Scan on product_details  (cost=9560.77..9704.28 rows=534 width=915)
                              Filter: ((NOT removed) AND (rev_out IS NULL) AND (effect_in <= '2010-11-29 13:14:55'::timestamp without time zone) AND (effect_out > '2010-11-29 13:14:55'::timestamp without time zone) AND (hashed subplan))
                              SubPlan
                                ->  Nested Loop  (cost=162.11..9543.20 rows=7030 width=4)
                                      ->  Hash Join  (cost=161.09..9401.58 rows=3515 width=4)
                                            Hash Cond: (public.branches.id = public.product_details.branch_id)
                                            ->  Seq Scan on branches  (cost=0.00..3816.56 rows=153965 width=4)
                                                  Filter: (context_id = 1)
                                            ->  Hash  (cost=117.15..117.15 rows=3515 width=4)
                                                  ->  Seq Scan on product_details  (cost=0.00..117.15 rows=3515 width=4)
                                      ->  Materialize  (cost=1.02..1.04 rows=2 width=0)
                                            ->  Seq Scan on contexts  (cost=0.00..1.02 rows=2 width=0)
            ->  Index Scan using bitemporals_pkey on bitemporals status_bitemporals_product_details  (cost=0.00..4.07 rows=1 width=95)
                  Index Cond: (status_bitemporals_product_details.id = product_details.status_bitemporal_id)
                  Filter: (status_bitemporals_product_details.type = 'StatusBitemporal'::text)
      ->  Index Scan using bitemporals_pkey on bitemporals  (cost=0.00..1.02 rows=1 width=95)
            Index Cond: (bitemporals.id = product_items.bitemporal_id)
            Filter: (bitemporals.type = 'ProductItemBitemporal'::text)
    And the differences are more substantial (as I said before, 1.5-2 sec. down to 100ms or so) depending on the item I'm looking at, this was just a convenient one that demonstrates the difference.

    Clearly the plans are different because of some very small changes, and I'm mainly looking to understand why that's the case, and if there's any way to get a consistently efficient plan out of the database without seemingly "tricking" it into a fast plan by putting an unused table in a FROM clause. Any ideas?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •