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. Of databases and the sacrifice of live chickens

Of databases and the sacrifice of live chickens

Scheduled Pinned Locked Moved Database
databasequestioncsshelplearning
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.
  • G Offline
    G Offline
    gantww
    wrote on last edited by
    #1

    I have a fairly simple stored proc in one of my databases that does a couple of simple inner joins and returns a result set. The proc accepts a user id and returns a set of gl accounts to which that user can apply invoices and such. When I pass in an admin user id, all the records come back instantly, no problem. When I use a user id with less elevated permissions, the query takes a minute and a half or more to run. Interestingly enough, if I take the SQL in the proc, and just run it outside the proc (setting the id of course), it returns instantly with either user id. It didn't even make a difference when I set the proc to run WITH RECOMPILE. Can someone give me a clue of what is going on here? I'm lost.

    M D W 3 Replies Last reply
    0
    • G gantww

      I have a fairly simple stored proc in one of my databases that does a couple of simple inner joins and returns a result set. The proc accepts a user id and returns a set of gl accounts to which that user can apply invoices and such. When I pass in an admin user id, all the records come back instantly, no problem. When I use a user id with less elevated permissions, the query takes a minute and a half or more to run. Interestingly enough, if I take the SQL in the proc, and just run it outside the proc (setting the id of course), it returns instantly with either user id. It didn't even make a difference when I set the proc to run WITH RECOMPILE. Can someone give me a clue of what is going on here? I'm lost.

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

      What are you using to filter the user permissions, I hope you have a table that links the GL accounts to a userid/group. When the admin is used there is no filter so instant response, if you filter the results SQL has to do a scan of the table to locate the GL accounts, put and index on the linking fields (userid, accountid etc) in the various tables. There will almost certainly be indexes on the primary tables (userid on user table, accountid on GL table) but the linking table may not have any indexes.

      Never underestimate the power of human stupidity RAH

      G 1 Reply Last reply
      0
      • G gantww

        I have a fairly simple stored proc in one of my databases that does a couple of simple inner joins and returns a result set. The proc accepts a user id and returns a set of gl accounts to which that user can apply invoices and such. When I pass in an admin user id, all the records come back instantly, no problem. When I use a user id with less elevated permissions, the query takes a minute and a half or more to run. Interestingly enough, if I take the SQL in the proc, and just run it outside the proc (setting the id of course), it returns instantly with either user id. It didn't even make a difference when I set the proc to run WITH RECOMPILE. Can someone give me a clue of what is going on here? I'm lost.

        D Offline
        D Offline
        David Skelly
        wrote on last edited by
        #3

        Without seeing the code for the stored proc it's hard to know what the problem is. Checking the indexes is good advice. If that doesn't work and you're still confused, you could try looking at the execution plan for the stored proc to see what it's actually doing. The SQL Server Query Analyzer lets you do this. Once you can see what the query is doing, you should have a better idea of how to fix it.

        1 Reply Last reply
        0
        • M Mycroft Holmes

          What are you using to filter the user permissions, I hope you have a table that links the GL accounts to a userid/group. When the admin is used there is no filter so instant response, if you filter the results SQL has to do a scan of the table to locate the GL accounts, put and index on the linking fields (userid, accountid etc) in the various tables. There will almost certainly be indexes on the primary tables (userid on user table, accountid on GL table) but the linking table may not have any indexes.

          Never underestimate the power of human stupidity RAH

          G Offline
          G Offline
          gantww
          wrote on last edited by
          #4

          Actually, whether the user is admin or not, the security mechanism is the same. They have permissions to access certain branches, and those branches have access to GL accounts. I checked the indexes and the estimated execution plans and didn't see anything strange. After some fighting with the system, it appears that all I had to do was declare a variable inside the stored procedure, set it to the value of one of the parameters and then use it in my select clause. For whatever reason, this fixed the issue (and so far, it hasn't popped up again). I'm guessing that it somehow managed to cache an execution plan that was inappropriate for the data it had. It's still very strange.

          1 Reply Last reply
          0
          • G gantww

            I have a fairly simple stored proc in one of my databases that does a couple of simple inner joins and returns a result set. The proc accepts a user id and returns a set of gl accounts to which that user can apply invoices and such. When I pass in an admin user id, all the records come back instantly, no problem. When I use a user id with less elevated permissions, the query takes a minute and a half or more to run. Interestingly enough, if I take the SQL in the proc, and just run it outside the proc (setting the id of course), it returns instantly with either user id. It didn't even make a difference when I set the proc to run WITH RECOMPILE. Can someone give me a clue of what is going on here? I'm lost.

            W Offline
            W Offline
            WoutL
            wrote on last edited by
            #5

            Maybe This[^] article can help.

            Wout Louwers

            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