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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Improve the speed of Function

Improve the speed of Function

Scheduled Pinned Locked Moved Database
databaseperformancetutorialannouncementcode-review
5 Posts 4 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
    member27
    wrote on last edited by
    #1

    Hi all , Iam Using a query which returns a bulk of data. first my query contains sub query to find the count so i panned to change as a function .. So i created a function which returns a table.. create function fnname returns table(name as varchar,....,....,...,...,...,...) I inserted the values into the temp table from the select query and (i want to find the count of receipt numbers so ... i updated the query with another query update temp table set rno =(select count(rno) from table where ....) then i executed the function but it is quite slow please suggest me any way to increase the speed of the function or query.. how to increase the speed of the function

    P M W 3 Replies Last reply
    0
    • M member27

      Hi all , Iam Using a query which returns a bulk of data. first my query contains sub query to find the count so i panned to change as a function .. So i created a function which returns a table.. create function fnname returns table(name as varchar,....,....,...,...,...,...) I inserted the values into the temp table from the select query and (i want to find the count of receipt numbers so ... i updated the query with another query update temp table set rno =(select count(rno) from table where ....) then i executed the function but it is quite slow please suggest me any way to increase the speed of the function or query.. how to increase the speed of the function

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      cbenan wrote:

      sub query

      X| Have you tried a join?

      1 Reply Last reply
      0
      • M member27

        Hi all , Iam Using a query which returns a bulk of data. first my query contains sub query to find the count so i panned to change as a function .. So i created a function which returns a table.. create function fnname returns table(name as varchar,....,....,...,...,...,...) I inserted the values into the temp table from the select query and (i want to find the count of receipt numbers so ... i updated the query with another query update temp table set rno =(select count(rno) from table where ....) then i executed the function but it is quite slow please suggest me any way to increase the speed of the function or query.. how to increase the speed of the function

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        It is unikely that the use of the function will affect the speed, it is more likely to be the number of times you call it. Quite often you can change the performance by totally restructuring your query. Break it down to part and do the part that reduces your data volume the most first. Try using the execution plan to identify table scans that do not use indexes. I have found the using table vars to hold large volumes is a disaster - I have gone back to #temp tables for anything over 2k rows. I also have no compunction about throwing an index onto a temp table. If you have 2005 then you may want to look at rownumber and partitioning in a query to get the count by invoices. Your question does not have 1 answer, this is where science turns into art, good luck!

        Never underestimate the power of human stupidity RAH

        M 1 Reply Last reply
        0
        • M member27

          Hi all , Iam Using a query which returns a bulk of data. first my query contains sub query to find the count so i panned to change as a function .. So i created a function which returns a table.. create function fnname returns table(name as varchar,....,....,...,...,...,...) I inserted the values into the temp table from the select query and (i want to find the count of receipt numbers so ... i updated the query with another query update temp table set rno =(select count(rno) from table where ....) then i executed the function but it is quite slow please suggest me any way to increase the speed of the function or query.. how to increase the speed of the function

          W Offline
          W Offline
          Wendelius
          wrote on last edited by
          #4

          Typically if you break down a single query to multiple different operations using a function or a procedure, the result can be slower. Because if you have separate SQL statements there's no way for the optimizer to search for the best plan to the whole query, only for the subcomponents. Also if you use temp tables and update and select them, you'll most likely cause physical I/O which may/may not be prevented when using a single query. Sometimes it's just impossible to write a single query for a certain task, but if you do have the opportunity, you should test the results using this approach (create a single query, combine few operations thus eliminating intermediate steps etc). Another thing is indexing. Make sure that you have adequate indexes and on the righ columns (or column combinations). For further details, I think you should post the code you currently have.

          The need to optimize rises from a bad design.My articles[^]

          1 Reply Last reply
          0
          • M Mycroft Holmes

            It is unikely that the use of the function will affect the speed, it is more likely to be the number of times you call it. Quite often you can change the performance by totally restructuring your query. Break it down to part and do the part that reduces your data volume the most first. Try using the execution plan to identify table scans that do not use indexes. I have found the using table vars to hold large volumes is a disaster - I have gone back to #temp tables for anything over 2k rows. I also have no compunction about throwing an index onto a temp table. If you have 2005 then you may want to look at rownumber and partitioning in a query to get the count by invoices. Your question does not have 1 answer, this is where science turns into art, good luck!

            Never underestimate the power of human stupidity RAH

            M Offline
            M Offline
            member27
            wrote on last edited by
            #5
            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