DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: Order of Joins Affecting Rewrite?

  1. #1
    Join Date
    Oct 2008
    Posts
    4

    Order of Joins Affecting Rewrite?

    Hello,

    I had a question come up from a developer today. He was trying to perform a query that included joining three tables (all inner joins) and depending on the order in which the tables are joined it affects whether the rewrite happens.The materialized view is a simple join of table A and table B.

    If the query is written as:

    select count(*)
    from tableA a inner join tableB b on a.ID=b.ID and a.price=b.price
    inner join tableC c on a.ID = c.ID
    /

    Then the query is rewritten to use the materialized view. If the query is written as:

    select count(*)
    from tableA a inner join tableC on a.ID=c.ID
    inner join tableB b on a.ID=b.ID and a.price=b.price
    /

    Then the rewrite does not happen at all. The query also takes quite a bit longer to complete.

    My first thought is that while the queries will ultimately produce the same results, the intermediate tables created during the joins are radically different and it seems reasonable that the difference may through off the optimizer. Could this likely be caused by a bug in the optimizer or is this just expected behavior?

  2. #2
    Join Date
    Mar 2007
    Location
    Ft. Lauderdale, FL
    Posts
    3,555
    First query exactly matches MV definition, that's why.
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.

Posting Permissions

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


Click Here to Expand Forum to Full Width