Derby
  1. Derby
  2. DERBY-6045

in list multi-probe by primary key not chosen on tables with >256 rows

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 10.9.1.0, 10.10.1.1
    • Fix Version/s: 10.8.3.3, 10.9.2.2, 10.11.0.0, 10.10.2.0
    • Component/s: SQL
    • Labels:
      None
    • Environment:
      Linux Debian 6.0.5
    • Issue & fix info:
      High Value Fix, Workaround attached
    • Bug behavior facts:
      Performance, Regression, Seen in production

      Description

      I have a table with a long integer primary key field and 11 million rows. I seem to be unable to load large chunks of rows via id in a reasonably efficient manner.

      1. If I do individual lookups via the primary key, then a fast indexed lookup occurs. However, if I do large numbers of such queries, then the time is overwhelmed by round-trip overhead which makes everything incredibly slow.

      2. If I use a single query with a disjunction of the primary keys of interest, then a table scan is performed (even if the clause only contains 1-3 items), which walks over 11 million rows...incredibly inefficient.

      3. If I use an IN clause, then a table scan is performed (even if the clause only contains 1-3 items), which walks over 11 million rows...incredibly inefficient.

      I'm guessing that this might have something to do with the fact that I'm using large integers and really big numbers that don't start anywhere at or about 1 for my keys. Could this possibly be confusing the optimizer?

      Here are the unlimited query plans for the 3 cases that I enumerated:
      *********************************************************************************************

      [EL Fine]: 2013-01-17 11:09:53.384-ServerSession(582235416)Connection(1430986883)Thread(Thread["Initial Lisp Listener",5,SubL Thread Group])-SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (TERM_ID = ?)
      bind => [2251799814033500]

      Thu Jan 17 11:09:53 CST 2013 Thread["Initial Lisp Listener",5,SubL Thread Group] (XID = 4711079), (SESSIONID = 3), SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (TERM_ID = ?) ******* Project-Restrict ResultSet (3):
      Number of opens = 1
      Rows seen = 1
      Rows filtered = 0
      restriction = false
      projection = true
      constructor time (milliseconds) = 0
      open time (milliseconds) = 0
      next time (milliseconds) = 0
      close time (milliseconds) = 0
      restriction time (milliseconds) = 0
      projection time (milliseconds) = 0
      optimizer estimated row count: 1.00
      optimizer estimated cost: 6.59
      Source result set:
      Index Row to Base Row ResultSet for FORMULA_TERM:
      Number of opens = 1
      Rows seen = 1
      Columns accessed from heap =

      {1, 2, 3, 4, 5, 6, 7, 8}

      constructor time (milliseconds) = 0
      open time (milliseconds) = 0
      next time (milliseconds) = 0
      close time (milliseconds) = 0
      optimizer estimated row count: 1.00
      optimizer estimated cost: 6.59
      Index Scan ResultSet for FORMULA_TERM using constraint KB_FORMULA_TERM_TERM_ID_PK at read committed isolation level using share row locking chosen by the optimizer
      Number of opens = 1
      Rows seen = 1
      Rows filtered = 0
      Fetch Size = 1
      constructor time (milliseconds) = 0
      open time (milliseconds) = 0
      next time (milliseconds) = 0
      close time (milliseconds) = 0
      next time in milliseconds/row = 0

      scan information:
      Bit set of columns fetched=All
      Number of columns fetched=2
      Number of deleted rows visited=0
      Number of pages visited=3
      Number of rows qualified=1
      Number of rows visited=1
      Scan type=btree
      Tree height=-1
      start position:
      >= on first 1 column(s).
      Ordered null semantics on the following columns:
      stop position:
      > on first 1 column(s).
      Ordered null semantics on the following columns:
      qualifiers:
      None
      optimizer estimated row count: 1.00
      optimizer estimated cost: 6.59

      [EL Fine]: 2013-01-17 11:01:00.732-ServerSession(1237006689)Connection(927179828)Thread(Thread["Initial Lisp Listener",5,SubL Thread Group])-SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (((TERM_ID = ?) OR (TERM_ID = ?)) OR (TERM_ID = ?))
      bind => [2251799814033500, 2251799814033501, 2251799814033499]

      Thu Jan 17 11:01:10 CST 2013 Thread["Initial Lisp Listener",5,SubL Thread Group] (XID = 4711078), (SESSIONID = 3), SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (((TERM_ID = ?) OR (TERM_ID = ?)) OR (TERM_ID = ?)) ******* Project-Restrict ResultSet (3):
      Number of opens = 1
      Rows seen = 3
      Rows filtered = 0
      restriction = false
      projection = true
      constructor time (milliseconds) = 0
      open time (milliseconds) = 0
      next time (milliseconds) = 0
      close time (milliseconds) = 0
      restriction time (milliseconds) = 0
      projection time (milliseconds) = 0
      optimizer estimated row count: 1176730.30
      optimizer estimated cost: 5931065.54
      Source result set:
      Project-Restrict ResultSet (2):
      Number of opens = 1
      Rows seen = 11767298
      Rows filtered = 11767295
      restriction = true
      projection = false
      constructor time (milliseconds) = 0
      open time (milliseconds) = 0
      next time (milliseconds) = 0
      close time (milliseconds) = 0
      restriction time (milliseconds) = 0
      projection time (milliseconds) = 0
      optimizer estimated row count: 1176730.30
      optimizer estimated cost: 5931065.54
      Source result set:
      Table Scan ResultSet for FORMULA_TERM at read committed isolation level using instantaneous share row locking chosen by the optimizer
      Number of opens = 1
      Rows seen = 11767298
      Rows filtered = 0
      Fetch Size = 16
      constructor time (milliseconds) = 0
      open time (milliseconds) = 0
      next time (milliseconds) = 0
      close time (milliseconds) = 0
      next time in milliseconds/row = 0

      scan information:
      Bit set of columns fetched=All
      Number of columns fetched=9
      Number of pages visited=34358
      Number of rows qualified=11767298
      Number of rows visited=11767298
      Scan type=heap
      start position:
      null
      stop position:
      null
      qualifiers:
      None
      optimizer estimated row count: 1176730.30
      optimizer estimated cost: 5931065.54

      [EL Fine]: 2013-01-17 11:27:00.627-ServerSession(1237006689)Connection(1688096771)Thread(Thread["Initial Lisp Listener",5,SubL Thread Group])-SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (TERM_ID IN (?,?,?))
      bind => [2251799814033500, 2251799814033501, 2251799814033499]

      Thu Jan 17 11:47:26 CST 2013 Thread["Initial Lisp Listener",5,SubL Thread Group] (XID = 4711080), (SESSIONID = 3), SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (TERM_ID IN (?,?,?)) ******* Project-Restrict ResultSet (3):
      Number of opens = 1
      Rows seen = 3
      Rows filtered = 0
      restriction = false
      projection = true
      constructor time (milliseconds) = 0
      open time (milliseconds) = 0
      next time (milliseconds) = 0
      close time (milliseconds) = 0
      restriction time (milliseconds) = 0
      projection time (milliseconds) = 0
      optimizer estimated row count: 1176730.30
      optimizer estimated cost: 5931065.54
      Source result set:
      Project-Restrict ResultSet (2):
      Number of opens = 1
      Rows seen = 11767298
      Rows filtered = 11767295
      restriction = true
      projection = false
      constructor time (milliseconds) = 0
      open time (milliseconds) = 0
      next time (milliseconds) = 0
      close time (milliseconds) = 0
      restriction time (milliseconds) = 0
      projection time (milliseconds) = 0
      optimizer estimated row count: 1176730.30
      optimizer estimated cost: 5931065.54
      Source result set:
      Table Scan ResultSet for FORMULA_TERM at read committed isolation level using instantaneous share row locking chosen by the optimizer
      Number of opens = 1
      Rows seen = 11767298
      Rows filtered = 0
      Fetch Size = 16
      constructor time (milliseconds) = 0
      open time (milliseconds) = 0
      next time (milliseconds) = 0
      close time (milliseconds) = 0
      next time in milliseconds/row = 0

      scan information:
      Bit set of columns fetched=All
      Number of columns fetched=9
      Number of pages visited=34358
      Number of rows qualified=11767298
      Number of rows visited=11767298
      Scan type=heap
      start position:
      null
      stop position:
      null
      qualifiers:
      None
      optimizer estimated row count: 1176730.30
      optimizer estimated cost: 5931065.54

      1. DERBY6045_patch1_diff.txt
        3 kB
        Mamta A. Satoor
      2. DERBY6045_patch2_diff.txt
        4 kB
        Mamta A. Satoor
      3. optimizerTraceOutputFor10_8.txt
        6 kB
        Mamta A. Satoor
      4. optimizerTraceOutputForTrunk.txt
        6 kB
        Mamta A. Satoor
      5. optimizerTraceOutputWithUpdateStatsFor10_8.txt
        6 kB
        Mamta A. Satoor
      6. optimizerTraceOutputWithUpdateStatsForTrunk.txt
        6 kB
        Mamta A. Satoor

        Issue Links

          Activity

          Tony Brusseau created issue -
          Tony Brusseau made changes -
          Field Original Value New Value
          Description I have a table with a long integer primary key field and 11 million rows. I seem to be unable to load large chunks of rows via id in a reasonably efficient manner.

            1. If I do individual lookups via the primary key, then a fast indexed lookup occurs. However, if I do large numbers of such queries, then the time is overwhelmed by round-trip overhead which makes everything incredibly slow.

            2. If I use a single query with a disjunction of the primary keys of interest, then a table scan is performed (even if the clause only contest 1-3 items), which walks over 11 million rows...incredibly inefficient.

            3. If I use an IN clause, then a table scan is performed (even if the clause only contest 1-3 items), which walks over 11 million rows...incredibly inefficient.

          Here are the unlimited query plans for the 3 cases that I enumerated:
          *********************************************************************************************

          [EL Fine]: 2013-01-17 11:09:53.384--ServerSession(582235416)--Connection(1430986883)--Thread(Thread["Initial Lisp Listener",5,SubL Thread Group])--SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (TERM_ID = ?)
          bind => [2251799814033500]

          Thu Jan 17 11:09:53 CST 2013 Thread["Initial Lisp Listener",5,SubL Thread Group] (XID = 4711079), (SESSIONID = 3), SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (TERM_ID = ?) ******* Project-Restrict ResultSet (3):
          Number of opens = 1
          Rows seen = 1
          Rows filtered = 0
          restriction = false
          projection = true
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1.00
          optimizer estimated cost: 6.59
          Source result set:
          Index Row to Base Row ResultSet for FORMULA_TERM:
          Number of opens = 1
          Rows seen = 1
          Columns accessed from heap = {1, 2, 3, 4, 5, 6, 7, 8}
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          optimizer estimated row count: 1.00
          optimizer estimated cost: 6.59
          Index Scan ResultSet for FORMULA_TERM using constraint KB_FORMULA_TERM_TERM_ID_PK at read committed isolation level using share row locking chosen by the optimizer
          Number of opens = 1
          Rows seen = 1
          Rows filtered = 0
          Fetch Size = 1
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          next time in milliseconds/row = 0

          scan information:
          Bit set of columns fetched=All
          Number of columns fetched=2
          Number of deleted rows visited=0
          Number of pages visited=3
          Number of rows qualified=1
          Number of rows visited=1
          Scan type=btree
          Tree height=-1
          start position:
          >= on first 1 column(s).
          Ordered null semantics on the following columns:
          stop position:
          > on first 1 column(s).
          Ordered null semantics on the following columns:
          qualifiers:
          None
          optimizer estimated row count: 1.00
          optimizer estimated cost: 6.59

          [EL Fine]: 2013-01-17 11:01:00.732--ServerSession(1237006689)--Connection(927179828)--Thread(Thread["Initial Lisp Listener",5,SubL Thread Group])--SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (((TERM_ID = ?) OR (TERM_ID = ?)) OR (TERM_ID = ?))
          bind => [2251799814033500, 2251799814033501, 2251799814033499]

          Thu Jan 17 11:01:10 CST 2013 Thread["Initial Lisp Listener",5,SubL Thread Group] (XID = 4711078), (SESSIONID = 3), SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (((TERM_ID = ?) OR (TERM_ID = ?)) OR (TERM_ID = ?)) ******* Project-Restrict ResultSet (3):
          Number of opens = 1
          Rows seen = 3
          Rows filtered = 0
          restriction = false
          projection = true
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          Source result set:
          Project-Restrict ResultSet (2):
          Number of opens = 1
          Rows seen = 11767298
          Rows filtered = 11767295
          restriction = true
          projection = false
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          Source result set:
          Table Scan ResultSet for FORMULA_TERM at read committed isolation level using instantaneous share row locking chosen by the optimizer
          Number of opens = 1
          Rows seen = 11767298
          Rows filtered = 0
          Fetch Size = 16
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          next time in milliseconds/row = 0

          scan information:
          Bit set of columns fetched=All
          Number of columns fetched=9
          Number of pages visited=34358
          Number of rows qualified=11767298
          Number of rows visited=11767298
          Scan type=heap
          start position:
          null
          stop position:
          null
          qualifiers:
          None
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54

          [EL Fine]: 2013-01-17 11:27:00.627--ServerSession(1237006689)--Connection(1688096771)--Thread(Thread["Initial Lisp Listener",5,SubL Thread Group])--SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (TERM_ID IN (?,?,?))
          bind => [2251799814033500, 2251799814033501, 2251799814033499]

          Thu Jan 17 11:47:26 CST 2013 Thread["Initial Lisp Listener",5,SubL Thread Group] (XID = 4711080), (SESSIONID = 3), SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (TERM_ID IN (?,?,?)) ******* Project-Restrict ResultSet (3):
          Number of opens = 1
          Rows seen = 3
          Rows filtered = 0
          restriction = false
          projection = true
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          Source result set:
          Project-Restrict ResultSet (2):
          Number of opens = 1
          Rows seen = 11767298
          Rows filtered = 11767295
          restriction = true
          projection = false
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          Source result set:
          Table Scan ResultSet for FORMULA_TERM at read committed isolation level using instantaneous share row locking chosen by the optimizer
          Number of opens = 1
          Rows seen = 11767298
          Rows filtered = 0
          Fetch Size = 16
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          next time in milliseconds/row = 0

          scan information:
          Bit set of columns fetched=All
          Number of columns fetched=9
          Number of pages visited=34358
          Number of rows qualified=11767298
          Number of rows visited=11767298
          Scan type=heap
          start position:
          null
          stop position:
          null
          qualifiers:
          None
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          I have a table with a long integer primary key field and 11 million rows. I seem to be unable to load large chunks of rows via id in a reasonably efficient manner.

            1. If I do individual lookups via the primary key, then a fast indexed lookup occurs. However, if I do large numbers of such queries, then the time is overwhelmed by round-trip overhead which makes everything incredibly slow.

            2. If I use a single query with a disjunction of the primary keys of interest, then a table scan is performed (even if the clause only contains 1-3 items), which walks over 11 million rows...incredibly inefficient.

            3. If I use an IN clause, then a table scan is performed (even if the clause only contains 1-3 items), which walks over 11 million rows...incredibly inefficient.

          Here are the unlimited query plans for the 3 cases that I enumerated:
          *********************************************************************************************

          [EL Fine]: 2013-01-17 11:09:53.384--ServerSession(582235416)--Connection(1430986883)--Thread(Thread["Initial Lisp Listener",5,SubL Thread Group])--SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (TERM_ID = ?)
          bind => [2251799814033500]

          Thu Jan 17 11:09:53 CST 2013 Thread["Initial Lisp Listener",5,SubL Thread Group] (XID = 4711079), (SESSIONID = 3), SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (TERM_ID = ?) ******* Project-Restrict ResultSet (3):
          Number of opens = 1
          Rows seen = 1
          Rows filtered = 0
          restriction = false
          projection = true
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1.00
          optimizer estimated cost: 6.59
          Source result set:
          Index Row to Base Row ResultSet for FORMULA_TERM:
          Number of opens = 1
          Rows seen = 1
          Columns accessed from heap = {1, 2, 3, 4, 5, 6, 7, 8}
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          optimizer estimated row count: 1.00
          optimizer estimated cost: 6.59
          Index Scan ResultSet for FORMULA_TERM using constraint KB_FORMULA_TERM_TERM_ID_PK at read committed isolation level using share row locking chosen by the optimizer
          Number of opens = 1
          Rows seen = 1
          Rows filtered = 0
          Fetch Size = 1
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          next time in milliseconds/row = 0

          scan information:
          Bit set of columns fetched=All
          Number of columns fetched=2
          Number of deleted rows visited=0
          Number of pages visited=3
          Number of rows qualified=1
          Number of rows visited=1
          Scan type=btree
          Tree height=-1
          start position:
          >= on first 1 column(s).
          Ordered null semantics on the following columns:
          stop position:
          > on first 1 column(s).
          Ordered null semantics on the following columns:
          qualifiers:
          None
          optimizer estimated row count: 1.00
          optimizer estimated cost: 6.59

          [EL Fine]: 2013-01-17 11:01:00.732--ServerSession(1237006689)--Connection(927179828)--Thread(Thread["Initial Lisp Listener",5,SubL Thread Group])--SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (((TERM_ID = ?) OR (TERM_ID = ?)) OR (TERM_ID = ?))
          bind => [2251799814033500, 2251799814033501, 2251799814033499]

          Thu Jan 17 11:01:10 CST 2013 Thread["Initial Lisp Listener",5,SubL Thread Group] (XID = 4711078), (SESSIONID = 3), SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (((TERM_ID = ?) OR (TERM_ID = ?)) OR (TERM_ID = ?)) ******* Project-Restrict ResultSet (3):
          Number of opens = 1
          Rows seen = 3
          Rows filtered = 0
          restriction = false
          projection = true
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          Source result set:
          Project-Restrict ResultSet (2):
          Number of opens = 1
          Rows seen = 11767298
          Rows filtered = 11767295
          restriction = true
          projection = false
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          Source result set:
          Table Scan ResultSet for FORMULA_TERM at read committed isolation level using instantaneous share row locking chosen by the optimizer
          Number of opens = 1
          Rows seen = 11767298
          Rows filtered = 0
          Fetch Size = 16
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          next time in milliseconds/row = 0

          scan information:
          Bit set of columns fetched=All
          Number of columns fetched=9
          Number of pages visited=34358
          Number of rows qualified=11767298
          Number of rows visited=11767298
          Scan type=heap
          start position:
          null
          stop position:
          null
          qualifiers:
          None
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54

          [EL Fine]: 2013-01-17 11:27:00.627--ServerSession(1237006689)--Connection(1688096771)--Thread(Thread["Initial Lisp Listener",5,SubL Thread Group])--SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (TERM_ID IN (?,?,?))
          bind => [2251799814033500, 2251799814033501, 2251799814033499]

          Thu Jan 17 11:47:26 CST 2013 Thread["Initial Lisp Listener",5,SubL Thread Group] (XID = 4711080), (SESSIONID = 3), SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (TERM_ID IN (?,?,?)) ******* Project-Restrict ResultSet (3):
          Number of opens = 1
          Rows seen = 3
          Rows filtered = 0
          restriction = false
          projection = true
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          Source result set:
          Project-Restrict ResultSet (2):
          Number of opens = 1
          Rows seen = 11767298
          Rows filtered = 11767295
          restriction = true
          projection = false
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          Source result set:
          Table Scan ResultSet for FORMULA_TERM at read committed isolation level using instantaneous share row locking chosen by the optimizer
          Number of opens = 1
          Rows seen = 11767298
          Rows filtered = 0
          Fetch Size = 16
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          next time in milliseconds/row = 0

          scan information:
          Bit set of columns fetched=All
          Number of columns fetched=9
          Number of pages visited=34358
          Number of rows qualified=11767298
          Number of rows visited=11767298
          Scan type=heap
          start position:
          null
          stop position:
          null
          qualifiers:
          None
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          Tony Brusseau made changes -
          Description I have a table with a long integer primary key field and 11 million rows. I seem to be unable to load large chunks of rows via id in a reasonably efficient manner.

            1. If I do individual lookups via the primary key, then a fast indexed lookup occurs. However, if I do large numbers of such queries, then the time is overwhelmed by round-trip overhead which makes everything incredibly slow.

            2. If I use a single query with a disjunction of the primary keys of interest, then a table scan is performed (even if the clause only contains 1-3 items), which walks over 11 million rows...incredibly inefficient.

            3. If I use an IN clause, then a table scan is performed (even if the clause only contains 1-3 items), which walks over 11 million rows...incredibly inefficient.

          Here are the unlimited query plans for the 3 cases that I enumerated:
          *********************************************************************************************

          [EL Fine]: 2013-01-17 11:09:53.384--ServerSession(582235416)--Connection(1430986883)--Thread(Thread["Initial Lisp Listener",5,SubL Thread Group])--SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (TERM_ID = ?)
          bind => [2251799814033500]

          Thu Jan 17 11:09:53 CST 2013 Thread["Initial Lisp Listener",5,SubL Thread Group] (XID = 4711079), (SESSIONID = 3), SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (TERM_ID = ?) ******* Project-Restrict ResultSet (3):
          Number of opens = 1
          Rows seen = 1
          Rows filtered = 0
          restriction = false
          projection = true
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1.00
          optimizer estimated cost: 6.59
          Source result set:
          Index Row to Base Row ResultSet for FORMULA_TERM:
          Number of opens = 1
          Rows seen = 1
          Columns accessed from heap = {1, 2, 3, 4, 5, 6, 7, 8}
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          optimizer estimated row count: 1.00
          optimizer estimated cost: 6.59
          Index Scan ResultSet for FORMULA_TERM using constraint KB_FORMULA_TERM_TERM_ID_PK at read committed isolation level using share row locking chosen by the optimizer
          Number of opens = 1
          Rows seen = 1
          Rows filtered = 0
          Fetch Size = 1
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          next time in milliseconds/row = 0

          scan information:
          Bit set of columns fetched=All
          Number of columns fetched=2
          Number of deleted rows visited=0
          Number of pages visited=3
          Number of rows qualified=1
          Number of rows visited=1
          Scan type=btree
          Tree height=-1
          start position:
          >= on first 1 column(s).
          Ordered null semantics on the following columns:
          stop position:
          > on first 1 column(s).
          Ordered null semantics on the following columns:
          qualifiers:
          None
          optimizer estimated row count: 1.00
          optimizer estimated cost: 6.59

          [EL Fine]: 2013-01-17 11:01:00.732--ServerSession(1237006689)--Connection(927179828)--Thread(Thread["Initial Lisp Listener",5,SubL Thread Group])--SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (((TERM_ID = ?) OR (TERM_ID = ?)) OR (TERM_ID = ?))
          bind => [2251799814033500, 2251799814033501, 2251799814033499]

          Thu Jan 17 11:01:10 CST 2013 Thread["Initial Lisp Listener",5,SubL Thread Group] (XID = 4711078), (SESSIONID = 3), SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (((TERM_ID = ?) OR (TERM_ID = ?)) OR (TERM_ID = ?)) ******* Project-Restrict ResultSet (3):
          Number of opens = 1
          Rows seen = 3
          Rows filtered = 0
          restriction = false
          projection = true
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          Source result set:
          Project-Restrict ResultSet (2):
          Number of opens = 1
          Rows seen = 11767298
          Rows filtered = 11767295
          restriction = true
          projection = false
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          Source result set:
          Table Scan ResultSet for FORMULA_TERM at read committed isolation level using instantaneous share row locking chosen by the optimizer
          Number of opens = 1
          Rows seen = 11767298
          Rows filtered = 0
          Fetch Size = 16
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          next time in milliseconds/row = 0

          scan information:
          Bit set of columns fetched=All
          Number of columns fetched=9
          Number of pages visited=34358
          Number of rows qualified=11767298
          Number of rows visited=11767298
          Scan type=heap
          start position:
          null
          stop position:
          null
          qualifiers:
          None
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54

          [EL Fine]: 2013-01-17 11:27:00.627--ServerSession(1237006689)--Connection(1688096771)--Thread(Thread["Initial Lisp Listener",5,SubL Thread Group])--SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (TERM_ID IN (?,?,?))
          bind => [2251799814033500, 2251799814033501, 2251799814033499]

          Thu Jan 17 11:47:26 CST 2013 Thread["Initial Lisp Listener",5,SubL Thread Group] (XID = 4711080), (SESSIONID = 3), SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (TERM_ID IN (?,?,?)) ******* Project-Restrict ResultSet (3):
          Number of opens = 1
          Rows seen = 3
          Rows filtered = 0
          restriction = false
          projection = true
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          Source result set:
          Project-Restrict ResultSet (2):
          Number of opens = 1
          Rows seen = 11767298
          Rows filtered = 11767295
          restriction = true
          projection = false
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          Source result set:
          Table Scan ResultSet for FORMULA_TERM at read committed isolation level using instantaneous share row locking chosen by the optimizer
          Number of opens = 1
          Rows seen = 11767298
          Rows filtered = 0
          Fetch Size = 16
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          next time in milliseconds/row = 0

          scan information:
          Bit set of columns fetched=All
          Number of columns fetched=9
          Number of pages visited=34358
          Number of rows qualified=11767298
          Number of rows visited=11767298
          Scan type=heap
          start position:
          null
          stop position:
          null
          qualifiers:
          None
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          I have a table with a long integer primary key field and 11 million rows. I seem to be unable to load large chunks of rows via id in a reasonably efficient manner.

            1. If I do individual lookups via the primary key, then a fast indexed lookup occurs. However, if I do large numbers of such queries, then the time is overwhelmed by round-trip overhead which makes everything incredibly slow.

            2. If I use a single query with a disjunction of the primary keys of interest, then a table scan is performed (even if the clause only contains 1-3 items), which walks over 11 million rows...incredibly inefficient.

            3. If I use an IN clause, then a table scan is performed (even if the clause only contains 1-3 items), which walks over 11 million rows...incredibly inefficient.

          I'm guessing that this might have something to do with the fact that I'm using large integers and really big numbers for my keys. Could this possibly be confusing the optimizer?

          Here are the unlimited query plans for the 3 cases that I enumerated:
          *********************************************************************************************

          [EL Fine]: 2013-01-17 11:09:53.384--ServerSession(582235416)--Connection(1430986883)--Thread(Thread["Initial Lisp Listener",5,SubL Thread Group])--SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (TERM_ID = ?)
          bind => [2251799814033500]

          Thu Jan 17 11:09:53 CST 2013 Thread["Initial Lisp Listener",5,SubL Thread Group] (XID = 4711079), (SESSIONID = 3), SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (TERM_ID = ?) ******* Project-Restrict ResultSet (3):
          Number of opens = 1
          Rows seen = 1
          Rows filtered = 0
          restriction = false
          projection = true
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1.00
          optimizer estimated cost: 6.59
          Source result set:
          Index Row to Base Row ResultSet for FORMULA_TERM:
          Number of opens = 1
          Rows seen = 1
          Columns accessed from heap = {1, 2, 3, 4, 5, 6, 7, 8}
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          optimizer estimated row count: 1.00
          optimizer estimated cost: 6.59
          Index Scan ResultSet for FORMULA_TERM using constraint KB_FORMULA_TERM_TERM_ID_PK at read committed isolation level using share row locking chosen by the optimizer
          Number of opens = 1
          Rows seen = 1
          Rows filtered = 0
          Fetch Size = 1
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          next time in milliseconds/row = 0

          scan information:
          Bit set of columns fetched=All
          Number of columns fetched=2
          Number of deleted rows visited=0
          Number of pages visited=3
          Number of rows qualified=1
          Number of rows visited=1
          Scan type=btree
          Tree height=-1
          start position:
          >= on first 1 column(s).
          Ordered null semantics on the following columns:
          stop position:
          > on first 1 column(s).
          Ordered null semantics on the following columns:
          qualifiers:
          None
          optimizer estimated row count: 1.00
          optimizer estimated cost: 6.59

          [EL Fine]: 2013-01-17 11:01:00.732--ServerSession(1237006689)--Connection(927179828)--Thread(Thread["Initial Lisp Listener",5,SubL Thread Group])--SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (((TERM_ID = ?) OR (TERM_ID = ?)) OR (TERM_ID = ?))
          bind => [2251799814033500, 2251799814033501, 2251799814033499]

          Thu Jan 17 11:01:10 CST 2013 Thread["Initial Lisp Listener",5,SubL Thread Group] (XID = 4711078), (SESSIONID = 3), SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (((TERM_ID = ?) OR (TERM_ID = ?)) OR (TERM_ID = ?)) ******* Project-Restrict ResultSet (3):
          Number of opens = 1
          Rows seen = 3
          Rows filtered = 0
          restriction = false
          projection = true
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          Source result set:
          Project-Restrict ResultSet (2):
          Number of opens = 1
          Rows seen = 11767298
          Rows filtered = 11767295
          restriction = true
          projection = false
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          Source result set:
          Table Scan ResultSet for FORMULA_TERM at read committed isolation level using instantaneous share row locking chosen by the optimizer
          Number of opens = 1
          Rows seen = 11767298
          Rows filtered = 0
          Fetch Size = 16
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          next time in milliseconds/row = 0

          scan information:
          Bit set of columns fetched=All
          Number of columns fetched=9
          Number of pages visited=34358
          Number of rows qualified=11767298
          Number of rows visited=11767298
          Scan type=heap
          start position:
          null
          stop position:
          null
          qualifiers:
          None
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54

          [EL Fine]: 2013-01-17 11:27:00.627--ServerSession(1237006689)--Connection(1688096771)--Thread(Thread["Initial Lisp Listener",5,SubL Thread Group])--SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (TERM_ID IN (?,?,?))
          bind => [2251799814033500, 2251799814033501, 2251799814033499]

          Thu Jan 17 11:47:26 CST 2013 Thread["Initial Lisp Listener",5,SubL Thread Group] (XID = 4711080), (SESSIONID = 3), SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (TERM_ID IN (?,?,?)) ******* Project-Restrict ResultSet (3):
          Number of opens = 1
          Rows seen = 3
          Rows filtered = 0
          restriction = false
          projection = true
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          Source result set:
          Project-Restrict ResultSet (2):
          Number of opens = 1
          Rows seen = 11767298
          Rows filtered = 11767295
          restriction = true
          projection = false
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          Source result set:
          Table Scan ResultSet for FORMULA_TERM at read committed isolation level using instantaneous share row locking chosen by the optimizer
          Number of opens = 1
          Rows seen = 11767298
          Rows filtered = 0
          Fetch Size = 16
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          next time in milliseconds/row = 0

          scan information:
          Bit set of columns fetched=All
          Number of columns fetched=9
          Number of pages visited=34358
          Number of rows qualified=11767298
          Number of rows visited=11767298
          Scan type=heap
          start position:
          null
          stop position:
          null
          qualifiers:
          None
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          Tony Brusseau made changes -
          Description I have a table with a long integer primary key field and 11 million rows. I seem to be unable to load large chunks of rows via id in a reasonably efficient manner.

            1. If I do individual lookups via the primary key, then a fast indexed lookup occurs. However, if I do large numbers of such queries, then the time is overwhelmed by round-trip overhead which makes everything incredibly slow.

            2. If I use a single query with a disjunction of the primary keys of interest, then a table scan is performed (even if the clause only contains 1-3 items), which walks over 11 million rows...incredibly inefficient.

            3. If I use an IN clause, then a table scan is performed (even if the clause only contains 1-3 items), which walks over 11 million rows...incredibly inefficient.

          I'm guessing that this might have something to do with the fact that I'm using large integers and really big numbers for my keys. Could this possibly be confusing the optimizer?

          Here are the unlimited query plans for the 3 cases that I enumerated:
          *********************************************************************************************

          [EL Fine]: 2013-01-17 11:09:53.384--ServerSession(582235416)--Connection(1430986883)--Thread(Thread["Initial Lisp Listener",5,SubL Thread Group])--SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (TERM_ID = ?)
          bind => [2251799814033500]

          Thu Jan 17 11:09:53 CST 2013 Thread["Initial Lisp Listener",5,SubL Thread Group] (XID = 4711079), (SESSIONID = 3), SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (TERM_ID = ?) ******* Project-Restrict ResultSet (3):
          Number of opens = 1
          Rows seen = 1
          Rows filtered = 0
          restriction = false
          projection = true
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1.00
          optimizer estimated cost: 6.59
          Source result set:
          Index Row to Base Row ResultSet for FORMULA_TERM:
          Number of opens = 1
          Rows seen = 1
          Columns accessed from heap = {1, 2, 3, 4, 5, 6, 7, 8}
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          optimizer estimated row count: 1.00
          optimizer estimated cost: 6.59
          Index Scan ResultSet for FORMULA_TERM using constraint KB_FORMULA_TERM_TERM_ID_PK at read committed isolation level using share row locking chosen by the optimizer
          Number of opens = 1
          Rows seen = 1
          Rows filtered = 0
          Fetch Size = 1
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          next time in milliseconds/row = 0

          scan information:
          Bit set of columns fetched=All
          Number of columns fetched=2
          Number of deleted rows visited=0
          Number of pages visited=3
          Number of rows qualified=1
          Number of rows visited=1
          Scan type=btree
          Tree height=-1
          start position:
          >= on first 1 column(s).
          Ordered null semantics on the following columns:
          stop position:
          > on first 1 column(s).
          Ordered null semantics on the following columns:
          qualifiers:
          None
          optimizer estimated row count: 1.00
          optimizer estimated cost: 6.59

          [EL Fine]: 2013-01-17 11:01:00.732--ServerSession(1237006689)--Connection(927179828)--Thread(Thread["Initial Lisp Listener",5,SubL Thread Group])--SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (((TERM_ID = ?) OR (TERM_ID = ?)) OR (TERM_ID = ?))
          bind => [2251799814033500, 2251799814033501, 2251799814033499]

          Thu Jan 17 11:01:10 CST 2013 Thread["Initial Lisp Listener",5,SubL Thread Group] (XID = 4711078), (SESSIONID = 3), SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (((TERM_ID = ?) OR (TERM_ID = ?)) OR (TERM_ID = ?)) ******* Project-Restrict ResultSet (3):
          Number of opens = 1
          Rows seen = 3
          Rows filtered = 0
          restriction = false
          projection = true
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          Source result set:
          Project-Restrict ResultSet (2):
          Number of opens = 1
          Rows seen = 11767298
          Rows filtered = 11767295
          restriction = true
          projection = false
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          Source result set:
          Table Scan ResultSet for FORMULA_TERM at read committed isolation level using instantaneous share row locking chosen by the optimizer
          Number of opens = 1
          Rows seen = 11767298
          Rows filtered = 0
          Fetch Size = 16
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          next time in milliseconds/row = 0

          scan information:
          Bit set of columns fetched=All
          Number of columns fetched=9
          Number of pages visited=34358
          Number of rows qualified=11767298
          Number of rows visited=11767298
          Scan type=heap
          start position:
          null
          stop position:
          null
          qualifiers:
          None
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54

          [EL Fine]: 2013-01-17 11:27:00.627--ServerSession(1237006689)--Connection(1688096771)--Thread(Thread["Initial Lisp Listener",5,SubL Thread Group])--SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (TERM_ID IN (?,?,?))
          bind => [2251799814033500, 2251799814033501, 2251799814033499]

          Thu Jan 17 11:47:26 CST 2013 Thread["Initial Lisp Listener",5,SubL Thread Group] (XID = 4711080), (SESSIONID = 3), SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (TERM_ID IN (?,?,?)) ******* Project-Restrict ResultSet (3):
          Number of opens = 1
          Rows seen = 3
          Rows filtered = 0
          restriction = false
          projection = true
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          Source result set:
          Project-Restrict ResultSet (2):
          Number of opens = 1
          Rows seen = 11767298
          Rows filtered = 11767295
          restriction = true
          projection = false
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          Source result set:
          Table Scan ResultSet for FORMULA_TERM at read committed isolation level using instantaneous share row locking chosen by the optimizer
          Number of opens = 1
          Rows seen = 11767298
          Rows filtered = 0
          Fetch Size = 16
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          next time in milliseconds/row = 0

          scan information:
          Bit set of columns fetched=All
          Number of columns fetched=9
          Number of pages visited=34358
          Number of rows qualified=11767298
          Number of rows visited=11767298
          Scan type=heap
          start position:
          null
          stop position:
          null
          qualifiers:
          None
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          I have a table with a long integer primary key field and 11 million rows. I seem to be unable to load large chunks of rows via id in a reasonably efficient manner.

            1. If I do individual lookups via the primary key, then a fast indexed lookup occurs. However, if I do large numbers of such queries, then the time is overwhelmed by round-trip overhead which makes everything incredibly slow.

            2. If I use a single query with a disjunction of the primary keys of interest, then a table scan is performed (even if the clause only contains 1-3 items), which walks over 11 million rows...incredibly inefficient.

            3. If I use an IN clause, then a table scan is performed (even if the clause only contains 1-3 items), which walks over 11 million rows...incredibly inefficient.

          I'm guessing that this might have something to do with the fact that I'm using large integers and really big numbers that don't start anywhere at or about 1 for my keys. Could this possibly be confusing the optimizer?

          Here are the unlimited query plans for the 3 cases that I enumerated:
          *********************************************************************************************

          [EL Fine]: 2013-01-17 11:09:53.384--ServerSession(582235416)--Connection(1430986883)--Thread(Thread["Initial Lisp Listener",5,SubL Thread Group])--SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (TERM_ID = ?)
          bind => [2251799814033500]

          Thu Jan 17 11:09:53 CST 2013 Thread["Initial Lisp Listener",5,SubL Thread Group] (XID = 4711079), (SESSIONID = 3), SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (TERM_ID = ?) ******* Project-Restrict ResultSet (3):
          Number of opens = 1
          Rows seen = 1
          Rows filtered = 0
          restriction = false
          projection = true
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1.00
          optimizer estimated cost: 6.59
          Source result set:
          Index Row to Base Row ResultSet for FORMULA_TERM:
          Number of opens = 1
          Rows seen = 1
          Columns accessed from heap = {1, 2, 3, 4, 5, 6, 7, 8}
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          optimizer estimated row count: 1.00
          optimizer estimated cost: 6.59
          Index Scan ResultSet for FORMULA_TERM using constraint KB_FORMULA_TERM_TERM_ID_PK at read committed isolation level using share row locking chosen by the optimizer
          Number of opens = 1
          Rows seen = 1
          Rows filtered = 0
          Fetch Size = 1
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          next time in milliseconds/row = 0

          scan information:
          Bit set of columns fetched=All
          Number of columns fetched=2
          Number of deleted rows visited=0
          Number of pages visited=3
          Number of rows qualified=1
          Number of rows visited=1
          Scan type=btree
          Tree height=-1
          start position:
          >= on first 1 column(s).
          Ordered null semantics on the following columns:
          stop position:
          > on first 1 column(s).
          Ordered null semantics on the following columns:
          qualifiers:
          None
          optimizer estimated row count: 1.00
          optimizer estimated cost: 6.59

          [EL Fine]: 2013-01-17 11:01:00.732--ServerSession(1237006689)--Connection(927179828)--Thread(Thread["Initial Lisp Listener",5,SubL Thread Group])--SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (((TERM_ID = ?) OR (TERM_ID = ?)) OR (TERM_ID = ?))
          bind => [2251799814033500, 2251799814033501, 2251799814033499]

          Thu Jan 17 11:01:10 CST 2013 Thread["Initial Lisp Listener",5,SubL Thread Group] (XID = 4711078), (SESSIONID = 3), SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (((TERM_ID = ?) OR (TERM_ID = ?)) OR (TERM_ID = ?)) ******* Project-Restrict ResultSet (3):
          Number of opens = 1
          Rows seen = 3
          Rows filtered = 0
          restriction = false
          projection = true
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          Source result set:
          Project-Restrict ResultSet (2):
          Number of opens = 1
          Rows seen = 11767298
          Rows filtered = 11767295
          restriction = true
          projection = false
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          Source result set:
          Table Scan ResultSet for FORMULA_TERM at read committed isolation level using instantaneous share row locking chosen by the optimizer
          Number of opens = 1
          Rows seen = 11767298
          Rows filtered = 0
          Fetch Size = 16
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          next time in milliseconds/row = 0

          scan information:
          Bit set of columns fetched=All
          Number of columns fetched=9
          Number of pages visited=34358
          Number of rows qualified=11767298
          Number of rows visited=11767298
          Scan type=heap
          start position:
          null
          stop position:
          null
          qualifiers:
          None
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54

          [EL Fine]: 2013-01-17 11:27:00.627--ServerSession(1237006689)--Connection(1688096771)--Thread(Thread["Initial Lisp Listener",5,SubL Thread Group])--SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (TERM_ID IN (?,?,?))
          bind => [2251799814033500, 2251799814033501, 2251799814033499]

          Thu Jan 17 11:47:26 CST 2013 Thread["Initial Lisp Listener",5,SubL Thread Group] (XID = 4711080), (SESSIONID = 3), SELECT TERM_ID, ARG0, ARG1, ARG2, ARG3, FORMULA_HASH, FORMULA_LENGTH, FORMULA_TYPE, KB_STATUS FROM KB.FORMULA_TERM WHERE (TERM_ID IN (?,?,?)) ******* Project-Restrict ResultSet (3):
          Number of opens = 1
          Rows seen = 3
          Rows filtered = 0
          restriction = false
          projection = true
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          Source result set:
          Project-Restrict ResultSet (2):
          Number of opens = 1
          Rows seen = 11767298
          Rows filtered = 11767295
          restriction = true
          projection = false
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          restriction time (milliseconds) = 0
          projection time (milliseconds) = 0
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          Source result set:
          Table Scan ResultSet for FORMULA_TERM at read committed isolation level using instantaneous share row locking chosen by the optimizer
          Number of opens = 1
          Rows seen = 11767298
          Rows filtered = 0
          Fetch Size = 16
          constructor time (milliseconds) = 0
          open time (milliseconds) = 0
          next time (milliseconds) = 0
          close time (milliseconds) = 0
          next time in milliseconds/row = 0

          scan information:
          Bit set of columns fetched=All
          Number of columns fetched=9
          Number of pages visited=34358
          Number of rows qualified=11767298
          Number of rows visited=11767298
          Scan type=heap
          start position:
          null
          stop position:
          null
          qualifiers:
          None
          optimizer estimated row count: 1176730.30
          optimizer estimated cost: 5931065.54
          Tony Brusseau made changes -
          Summary Can't bulk load terms by primary key efficiently Can't bulk load terms by primary key efficiently on tables >256 rows
          Tony Brusseau made changes -
          Summary Can't bulk load terms by primary key efficiently on tables >256 rows Can't bulk load rows by primary key efficiently on tables with >256 rows
          Mike Matrigali made changes -
          Link This issue is related to DERBY-47 [ DERBY-47 ]
          Mike Matrigali made changes -
          Summary Can't bulk load rows by primary key efficiently on tables with >256 rows in list multi-probe by primary key not chosen on tables with >256 rows
          Mamta A. Satoor made changes -
          Bug behavior facts Regression [ 10420 ]
          Affects Version/s 10.10.0.0 [ 12321550 ]
          Mamta A. Satoor made changes -
          Link This issue relates to DERBY-3790 [ DERBY-3790 ]
          Mike Matrigali made changes -
          Bug behavior facts Regression [ 10420 ] Performance,Regression,Seen in production [ 10362, 10420, 10421 ]
          Issue & fix info High Value Fix [ 10422 ]
          Kristian Waagan made changes -
          Urgency Urgent [ 10051 ]
          Issue & fix info High Value Fix [ 10422 ] High Value Fix,Workaround attached [ 10422, 10427 ]
          Priority Critical [ 2 ] Major [ 3 ]
          Mamta A. Satoor made changes -
          Attachment optimizerTraceOutputFor10_8.txt [ 12572025 ]
          Attachment optimizerTraceOutputForTrunk.txt [ 12572026 ]
          Mamta A. Satoor made changes -
          Mamta A. Satoor made changes -
          Attachment DERBY6045_patch1_diff.txt [ 12573199 ]
          Mamta A. Satoor made changes -
          Attachment DERBY6045_patch2_diff.txt [ 12574847 ]
          Mamta A. Satoor made changes -
          Fix Version/s 10.11.0.0 [ 12324243 ]
          Mamta A. Satoor made changes -
          Link This issue is related to DERBY-6156 [ DERBY-6156 ]
          Mike Matrigali made changes -
          Component/s SQL [ 11408 ]
          Component/s Store [ 11412 ]
          Mamta A. Satoor made changes -
          Fix Version/s 10.10.1.2 [ 12324247 ]
          Mamta A. Satoor made changes -
          Fix Version/s 10.9.2.2 [ 12323562 ]
          Mamta A. Satoor made changes -
          Assignee Mamta A. Satoor [ mamtas ]
          Mamta A. Satoor made changes -
          Fix Version/s 10.8.3.1 [ 12323475 ]
          Tony Brusseau made changes -
          Attachment table.del [ 12584035 ]
          Mike Matrigali made changes -
          Link This issue relates to DERBY-6226 [ DERBY-6226 ]
          Tony Brusseau made changes -
          Attachment table.del [ 12584035 ]
          Mamta A. Satoor made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Gavin made changes -
          Workflow jira [ 12746495 ] Default workflow, editable Closed status [ 12802262 ]
          Myrna van Lunteren made changes -
          Fix Version/s 10.10.2.0 [ 12326659 ]
          Fix Version/s 10.10.1.4 [ 12324247 ]

            People

            • Assignee:
              Mamta A. Satoor
              Reporter:
              Tony Brusseau
            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development