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. Query / Design Optimization help

Query / Design Optimization help

Scheduled Pinned Locked Moved Database
databasehelpdesignalgorithmsperformance
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.
  • L Offline
    L Offline
    Laddie
    wrote on last edited by
    #1

    I have a situation where i need to optimize the query to perform better. possibly a solution. Here is the situation. I have a table with the following fields(I am putting only those are significant to the scenirio) WorkItems[Table] StartDate EndDate Stage CompletedDate I need to calculate a value named status according to various conditions involving the above parameters. Like If StartDate < getdate() Status = Green etc.. I created a function called CalculateStatus Passing all the above parameters and added one computed colum in the WorkItems table to call this function. Since column is non deterministic i cant add a index to this column. Now when i blindly do a select of status the same is getting calculated very fast The issue is when i use this computed column with aggragate function like 1) SELECT count(Status) FROM WorkItems Or when doing a group by 2) SELECT Count(WorkItemId),Status FROM WorkITems Group BY Status Could you please guid me how i could optimize the situation so that i can make things faster. Thanks in advance for your valuable time Sreehari ARanghat

    Thanks Laddie Kindly rate if the answer was helpful

    C 1 Reply Last reply
    0
    • L Laddie

      I have a situation where i need to optimize the query to perform better. possibly a solution. Here is the situation. I have a table with the following fields(I am putting only those are significant to the scenirio) WorkItems[Table] StartDate EndDate Stage CompletedDate I need to calculate a value named status according to various conditions involving the above parameters. Like If StartDate < getdate() Status = Green etc.. I created a function called CalculateStatus Passing all the above parameters and added one computed colum in the WorkItems table to call this function. Since column is non deterministic i cant add a index to this column. Now when i blindly do a select of status the same is getting calculated very fast The issue is when i use this computed column with aggragate function like 1) SELECT count(Status) FROM WorkItems Or when doing a group by 2) SELECT Count(WorkItemId),Status FROM WorkITems Group BY Status Could you please guid me how i could optimize the situation so that i can make things faster. Thanks in advance for your valuable time Sreehari ARanghat

      Thanks Laddie Kindly rate if the answer was helpful

      C Offline
      C Offline
      Chris Meech
      wrote on last edited by
      #2

      Instead of a computed column, use a normal column and use an after update/insert trigger on the table that calls your function and sets the column value for the row in question. You then also have the advantage of adding an index on this column. :)

      Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]

      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