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. Performance question

Performance question

Scheduled Pinned Locked Moved Database
questionsharepointperformance
5 Posts 5 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.
  • J Offline
    J Offline
    Johnny J
    wrote on last edited by
    #1

    If you have a SP where you (among other things) need to extract the number of a certain rowtype, and you do this: SELECT a, b, c, d, (SELECT COUNT(*) FROM table1 WHERE my_condition1=1) AS FooBarCount, e, f FROM table2 WHERE my_condition2=1; it seems to me that the performance ought to be remarkably slower than if you do: SELECT a, b, c, d, (SELECT COUNT(table1s_indexed_column) FROM table1 WHERE my_condition1=1) AS FooBarCount, e, f FROM table2 WHERE my_condition2=1; At least according to everything I've learnt until now. Can anybody confirm if I'm right or not?

    Why can't I be applicable like John? - Me, April 2011
    -----
    Beidh ceol, caint agus craic againn - Seán Bán Breathnach
    -----
    Da mihi sis crustum Etruscum cum omnibus in eo!
    -----
    Everybody is ignorant, only on different subjects - Will Rogers, 1924

    P D D S 4 Replies Last reply
    0
    • J Johnny J

      If you have a SP where you (among other things) need to extract the number of a certain rowtype, and you do this: SELECT a, b, c, d, (SELECT COUNT(*) FROM table1 WHERE my_condition1=1) AS FooBarCount, e, f FROM table2 WHERE my_condition2=1; it seems to me that the performance ought to be remarkably slower than if you do: SELECT a, b, c, d, (SELECT COUNT(table1s_indexed_column) FROM table1 WHERE my_condition1=1) AS FooBarCount, e, f FROM table2 WHERE my_condition2=1; At least according to everything I've learnt until now. Can anybody confirm if I'm right or not?

      Why can't I be applicable like John? - Me, April 2011
      -----
      Beidh ceol, caint agus craic againn - Seán Bán Breathnach
      -----
      Da mihi sis crustum Etruscum cum omnibus in eo!
      -----
      Everybody is ignorant, only on different subjects - Will Rogers, 1924

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

      It depends. But in general, I wouldn't expect so. But that's some weird code, there must be a better way.

      1 Reply Last reply
      0
      • J Johnny J

        If you have a SP where you (among other things) need to extract the number of a certain rowtype, and you do this: SELECT a, b, c, d, (SELECT COUNT(*) FROM table1 WHERE my_condition1=1) AS FooBarCount, e, f FROM table2 WHERE my_condition2=1; it seems to me that the performance ought to be remarkably slower than if you do: SELECT a, b, c, d, (SELECT COUNT(table1s_indexed_column) FROM table1 WHERE my_condition1=1) AS FooBarCount, e, f FROM table2 WHERE my_condition2=1; At least according to everything I've learnt until now. Can anybody confirm if I'm right or not?

        Why can't I be applicable like John? - Me, April 2011
        -----
        Beidh ceol, caint agus craic againn - Seán Bán Breathnach
        -----
        Da mihi sis crustum Etruscum cum omnibus in eo!
        -----
        Everybody is ignorant, only on different subjects - Will Rogers, 1924

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

        I can't answer your question with 100% certainty, but you should explore the SQL Profiler and run your queries through them to see what execution plan is choosen. Remember that just because an index exists, the optimizer may choose not to use it; resulting in a table scan. Experiment with SQL Profiler and you can learn alot. Good luck. :thumbsup:

        1 Reply Last reply
        0
        • J Johnny J

          If you have a SP where you (among other things) need to extract the number of a certain rowtype, and you do this: SELECT a, b, c, d, (SELECT COUNT(*) FROM table1 WHERE my_condition1=1) AS FooBarCount, e, f FROM table2 WHERE my_condition2=1; it seems to me that the performance ought to be remarkably slower than if you do: SELECT a, b, c, d, (SELECT COUNT(table1s_indexed_column) FROM table1 WHERE my_condition1=1) AS FooBarCount, e, f FROM table2 WHERE my_condition2=1; At least according to everything I've learnt until now. Can anybody confirm if I'm right or not?

          Why can't I be applicable like John? - Me, April 2011
          -----
          Beidh ceol, caint agus craic againn - Seán Bán Breathnach
          -----
          Da mihi sis crustum Etruscum cum omnibus in eo!
          -----
          Everybody is ignorant, only on different subjects - Will Rogers, 1924

          D Offline
          D Offline
          dasblinkenlight
          wrote on last edited by
          #4

          I read somewhere[^] that the difference between count(*) and count(1) or count(indexed_column) is not nearly as relevant now as it used to be in the past. Basically, once the writers of the database engines learned of the problem, they quietly fixed it. The habit of writing count(1), however, outlived the bug. In the late nineties, using count(indexed_column) or count(1) would make queries a lot faster on many commercial engines (e.g. Oracle-7). At this point, however, most modern DB engines with the "non-toy" status should prefer count(*) to count(1).

          1 Reply Last reply
          0
          • J Johnny J

            If you have a SP where you (among other things) need to extract the number of a certain rowtype, and you do this: SELECT a, b, c, d, (SELECT COUNT(*) FROM table1 WHERE my_condition1=1) AS FooBarCount, e, f FROM table2 WHERE my_condition2=1; it seems to me that the performance ought to be remarkably slower than if you do: SELECT a, b, c, d, (SELECT COUNT(table1s_indexed_column) FROM table1 WHERE my_condition1=1) AS FooBarCount, e, f FROM table2 WHERE my_condition2=1; At least according to everything I've learnt until now. Can anybody confirm if I'm right or not?

            Why can't I be applicable like John? - Me, April 2011
            -----
            Beidh ceol, caint agus craic againn - Seán Bán Breathnach
            -----
            Da mihi sis crustum Etruscum cum omnibus in eo!
            -----
            Everybody is ignorant, only on different subjects - Will Rogers, 1924

            S Offline
            S Offline
            SilimSayo
            wrote on last edited by
            #5

            I don't know what the performance would be like but your code seems a bit weired. Does table1 and table2 have any relationship(column[s]) in common? it seems to be you're going to end up with a cartesian product of some sort.

            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