Same or different execution plan for similar looking SQL Statements?

  • Just have 1 quick question. As far as I understand that SQL Server keeps the plan for constantly running queries, SP etc, so does SQL Server have the same or different plan for these SQL Statements.

    (@P0 bigint,@P1 bigint)

    SELECT "VALUE" AS Audit_Object_Type

    FROM field_enum_values

    WHERE fieldId = @P0

    AND enumId = @P1

    (@P0 bigint,@P1 bigint)

    SELECT "VALUE" AS Field_Type

    FROM field_enum_values

    WHERE fieldId = @P0

    AND enumId = @P1

    "He who learns for the sake of haughtiness, dies ignorant. He who learns only to talk, rather than to act, dies a hyprocite. He who learns for the mere sake of debating, dies irreligious. He who learns only to accumulate wealth, dies an atheist. And he who learns for the sake of action, dies a mystic."[/i]

  • Not sure. I suggest running both queries and then looking at the plan cache:

    SELECT ecp.usecounts, ecp.cacheobjtype, ecp.objtype, est.text

    FROM sys.dm_exec_cached_plans ecp

    CROSS APPLY sys.dm_exec_sql_text(plan_handle) est

    WHERE est.text LIKE '%field_enum_values%'

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.

  • It's probably the same plan, but there will be two of them because you have what would be considered two different queries because of the different aliases.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Different entries in the plan cache, very likely the same plan form, but two different plan objects in cache.

    The queries would have to be an exact text match to have the same plan entry in cache.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply