Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. whats diffrence between in two query in performance respect

whats diffrence between in two query in performance respect

Scheduled Pinned Locked Moved Database
databaseperformance
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mhd sbt
    wrote on last edited by
    #1

    hi to all whats diffrence between two below query in performance respect: query 1:

    SELECT n, dbo.AddOne(n) AS r
    FROM dbo.T1
    ORDER BY r;

    function addOne is this:

    CREATE FUNCTION dbo.AddOneInline(@n AS BIGINT) RETURNS TABLE
    AS
    RETURN SELECT @n + 1 AS val;
    GO

    and query2:

    SELECT n, (SELECT val FROM dbo.AddOneInline(n)) AS r
    FROM dbo.T1
    ORDER BY r;

    and defination of function is:

    GO
    CREATE FUNCTION dbo.AddOneInline(@n AS BIGINT) RETURNS TABLE
    AS
    RETURN SELECT @n + 1 AS val;
    GO

    query 2 is very good in performance and i want to know whats difference between in this two query

    L 1 Reply Last reply
    0
    • M mhd sbt

      hi to all whats diffrence between two below query in performance respect: query 1:

      SELECT n, dbo.AddOne(n) AS r
      FROM dbo.T1
      ORDER BY r;

      function addOne is this:

      CREATE FUNCTION dbo.AddOneInline(@n AS BIGINT) RETURNS TABLE
      AS
      RETURN SELECT @n + 1 AS val;
      GO

      and query2:

      SELECT n, (SELECT val FROM dbo.AddOneInline(n)) AS r
      FROM dbo.T1
      ORDER BY r;

      and defination of function is:

      GO
      CREATE FUNCTION dbo.AddOneInline(@n AS BIGINT) RETURNS TABLE
      AS
      RETURN SELECT @n + 1 AS val;
      GO

      query 2 is very good in performance and i want to know whats difference between in this two query

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      The difference is that one is written out as a subquery. It's a micro-optimization IMHO, but you can use the Management Studio[^] to check the execution plan and compare both versions.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups