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. General Programming
  3. Java
  4. Memory usage for requested rows from database

Memory usage for requested rows from database

Scheduled Pinned Locked Moved Java
javadatabaseregexperformancequestion
6 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.
  • V Offline
    V Offline
    Valentinor
    wrote on last edited by
    #1

    When you are running in Java:

    ResultSet rs = stmt.executeQuery("SELECT Column FROM Table WHERE Condition");

    Does the database create in memory a list with all the rows/values that have the given condition, and it is keeping that list until the rs is close? Or it will only keep the first value, and move to the next value when rs.next() is called? I'm asking this because you can give it the command to FETCH NEXT X ROWS ONLY, and in case you have a database with millions of entries, that would save time and resources when you only want X rows, and not all of them that match the given condition. Or the FETCH is only a hard limit to know when to stop with sending the rows/values one by one?

    J R K 3 Replies Last reply
    0
    • V Valentinor

      When you are running in Java:

      ResultSet rs = stmt.executeQuery("SELECT Column FROM Table WHERE Condition");

      Does the database create in memory a list with all the rows/values that have the given condition, and it is keeping that list until the rs is close? Or it will only keep the first value, and move to the next value when rs.next() is called? I'm asking this because you can give it the command to FETCH NEXT X ROWS ONLY, and in case you have a database with millions of entries, that would save time and resources when you only want X rows, and not all of them that match the given condition. Or the FETCH is only a hard limit to know when to stop with sending the rows/values one by one?

      J Offline
      J Offline
      jschell
      wrote on last edited by
      #2

      Valentinor wrote:

      SELECT Column FROM Table WHERE Condition

      First keep in mind that is SQL. It is sent as is to the database.

      Valentinor wrote:

      Does the database create in memory a list with all the rows/values that have the given condition

      That is not how the jdbc is defined to work. But a bad driver could definitely do that. There is (or was) a jdbc/odbc 'text' driver and presumably it could have loaded everything into memory. But that was basically a toy anyways. The next() technically loads it. But drivers I have actually looked at usually use some sort of batch request that might load 10, 100, etc, and then wait for the next to pull from the local set. I think I even recall somewhere that can be adjusted. The initial set as somewhat low value.

      Valentinor wrote:

      FETCH NEXT X ROWS ONLY

      How you do that depends on the database (see above). But every query you write should always be constrained (the where clause) and most should have a limit on the number of rows. The result should be paged. Only time that would not be true when you know for a fact that the target table has an extraordinarily low growth factor. Only ones I know for sure like that are application enumeration tables. Table examples where you should ALWAYS include the paging mechanism are things like customers, users, orders, events, etc.

      Valentinor wrote:

      database with millions of entries, that would save time and resources when you only want X rows,

      That is a complex statement and there is no simple answer. You should NEVER, for example, allow for a design where a UI could expect a user to view 'millions' of rows. As a developer if you see a requirement like that you should insist that the requirements be changed to include reasonable constraint restrictions. Some examples 1. Require a date range, account number, customer store, etc. 2. Do a count(*) with the constraints in place and throw an error if the result is larger than X (say 10,000) which would then require the user (in the UI) to add more constraints to narrow the result. And such queries should ALWAYS require a page and row size. So for example 'page 5', 'size 20'. The backend then restricts (hard code) the max size to something like 1000. Additionally the users (whoever they are) might claim that the

      V 1 Reply Last reply
      0
      • J jschell

        Valentinor wrote:

        SELECT Column FROM Table WHERE Condition

        First keep in mind that is SQL. It is sent as is to the database.

        Valentinor wrote:

        Does the database create in memory a list with all the rows/values that have the given condition

        That is not how the jdbc is defined to work. But a bad driver could definitely do that. There is (or was) a jdbc/odbc 'text' driver and presumably it could have loaded everything into memory. But that was basically a toy anyways. The next() technically loads it. But drivers I have actually looked at usually use some sort of batch request that might load 10, 100, etc, and then wait for the next to pull from the local set. I think I even recall somewhere that can be adjusted. The initial set as somewhat low value.

        Valentinor wrote:

        FETCH NEXT X ROWS ONLY

        How you do that depends on the database (see above). But every query you write should always be constrained (the where clause) and most should have a limit on the number of rows. The result should be paged. Only time that would not be true when you know for a fact that the target table has an extraordinarily low growth factor. Only ones I know for sure like that are application enumeration tables. Table examples where you should ALWAYS include the paging mechanism are things like customers, users, orders, events, etc.

        Valentinor wrote:

        database with millions of entries, that would save time and resources when you only want X rows,

        That is a complex statement and there is no simple answer. You should NEVER, for example, allow for a design where a UI could expect a user to view 'millions' of rows. As a developer if you see a requirement like that you should insist that the requirements be changed to include reasonable constraint restrictions. Some examples 1. Require a date range, account number, customer store, etc. 2. Do a count(*) with the constraints in place and throw an error if the result is larger than X (say 10,000) which would then require the user (in the UI) to add more constraints to narrow the result. And such queries should ALWAYS require a page and row size. So for example 'page 5', 'size 20'. The backend then restricts (hard code) the max size to something like 1000. Additionally the users (whoever they are) might claim that the

        V Offline
        V Offline
        Valentinor
        wrote on last edited by
        #3

        jschell wrote:

        That is not how the jdbc is defined to work.

        OK, good. I'm the only developer for now, so I'm working on everything, and DB/SQL isn't something I'm good at, but I don't want to make a bad DB when it comes to performance.

        jschell wrote:

        But a bad driver could definitely do that.

        I'm using Oracle JDBC driver 11, so I would say that is out of the question.

        jschell wrote:

        The result should be paged.

        Is this a good example of paging?[^] Unfortunately, that isn't something I know of.

        jschell wrote:

        You should NEVER, for example, allow for a design where a UI could expect a user to view 'millions' of rows.

        Oh, no way that. By that I meant something else, but you answered it here:

        jschell wrote:

        That is not how the jdbc is defined to work. But a bad driver could definitely do that.

        Thank you for all the info!

        J 1 Reply Last reply
        0
        • V Valentinor

          jschell wrote:

          That is not how the jdbc is defined to work.

          OK, good. I'm the only developer for now, so I'm working on everything, and DB/SQL isn't something I'm good at, but I don't want to make a bad DB when it comes to performance.

          jschell wrote:

          But a bad driver could definitely do that.

          I'm using Oracle JDBC driver 11, so I would say that is out of the question.

          jschell wrote:

          The result should be paged.

          Is this a good example of paging?[^] Unfortunately, that isn't something I know of.

          jschell wrote:

          You should NEVER, for example, allow for a design where a UI could expect a user to view 'millions' of rows.

          Oh, no way that. By that I meant something else, but you answered it here:

          jschell wrote:

          That is not how the jdbc is defined to work. But a bad driver could definitely do that.

          Thank you for all the info!

          J Offline
          J Offline
          jschell
          wrote on last edited by
          #4

          Valentinor wrote:

          Is this a good example of paging?[^]

          Using the following in google to look for examples.

          PLSQL paging query

          1 Reply Last reply
          0
          • V Valentinor

            When you are running in Java:

            ResultSet rs = stmt.executeQuery("SELECT Column FROM Table WHERE Condition");

            Does the database create in memory a list with all the rows/values that have the given condition, and it is keeping that list until the rs is close? Or it will only keep the first value, and move to the next value when rs.next() is called? I'm asking this because you can give it the command to FETCH NEXT X ROWS ONLY, and in case you have a database with millions of entries, that would save time and resources when you only want X rows, and not all of them that match the given condition. Or the FETCH is only a hard limit to know when to stop with sending the rows/values one by one?

            R Offline
            R Offline
            RedDk
            wrote on last edited by
            #5

            There's a phrase in TSQL parlance: "Row by Agonizing Row" (In order to give proper credit to the conspiracy that does the stabbing here I'd have to misquote someone so I'll just type in stuff which an eleventh grade high school teacher could type if she were quoting herself). Look up INDEX and think "I'll use INDEX, in 'automatic assign of an index' and just DROP the original index and reassign it after I do all the tabulation"

            1 Reply Last reply
            0
            • V Valentinor

              When you are running in Java:

              ResultSet rs = stmt.executeQuery("SELECT Column FROM Table WHERE Condition");

              Does the database create in memory a list with all the rows/values that have the given condition, and it is keeping that list until the rs is close? Or it will only keep the first value, and move to the next value when rs.next() is called? I'm asking this because you can give it the command to FETCH NEXT X ROWS ONLY, and in case you have a database with millions of entries, that would save time and resources when you only want X rows, and not all of them that match the given condition. Or the FETCH is only a hard limit to know when to stop with sending the rows/values one by one?

              K Offline
              K Offline
              kdbueno
              wrote on last edited by
              #6

              depends on object rule, but not all object oriented programming rules, bind heaps into contusion of hcl.

              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