Home Forums SQL Server 2016 SQL Server 2016 - Development and T-SQL Odd behavior -- execution plan different when I execute in the target database vs not in the target database RE: Odd behavior -- execution plan different when I execute in the target database vs not in the target database

  • To clarify, I'm running the exact same query, against the exact same database target.  It's just the explain plan differs significantly in cost whether or not I have the correct database selected in the context dropdown in the upper left in SSMS.

    Attached are the two plans.  Good.sqlplan is when I'm in DataMart in the drop down DB context (and the query points to data in the DataMart database), Bad.sqlplan is when I'm in a different database context, but it's still the same query as Good.sqlplan.

    I'm baffled still.  I've tried updating stats on DataMart, no luck.