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. Billion rows

Billion rows

Scheduled Pinned Locked Moved Database
databasequestionmysqldesigncloud
21 Posts 3 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 jschell

    Ok. Per the OP table looks like the following

    Table T
    id char(22)
    RefId1 char(22)
    RefId2 char(22)

    I need to do the following 1. Verify that RefId1 and RefId2 are in a different table either in that order (1,2) or (2,1) 2. Report if neither or only one id is found. 3. Report if more than one match is found 4. If found report if a different column (not documented above) is same as in the second table. The second table also has a billion rows. Both tables have indexes on the id, and the two other columns documented above.

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

    oh that is ugly - the 1,2 - 2,1 is going to cost you. Can you do it in a couple of steps, inner join on the 2 layouts and eliminate them from the process, possibly even move the non matching records into another table for your reporting analysis (one assumes the majority have valid matching records).

    Never underestimate the power of human stupidity RAH

    J 1 Reply Last reply
    0
    • M Mycroft Holmes

      oh that is ugly - the 1,2 - 2,1 is going to cost you. Can you do it in a couple of steps, inner join on the 2 layouts and eliminate them from the process, possibly even move the non matching records into another table for your reporting analysis (one assumes the majority have valid matching records).

      Never underestimate the power of human stupidity RAH

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

      Mycroft Holmes wrote:

      oh that is ugly - the 1,2 - 2,1 is going to cost you.

      Yep - not my design.

      Mycroft Holmes wrote:

      Can you do it in a couple of steps, inner join on the 2 layouts and eliminate them from the process,

      I suspect that join between the two tables will return on the order of a billion rows. Either because there are very few rows that are not matched or there are zero. I am only expecting the first because with legacy data orphans might occur.

      Mycroft Holmes wrote:

      possibly even move the non matching records

      I have to find them first. Once I find them I don't consider the analysis to be a problem. Actually for those that do not match I consider it likely they are orphans.

      M 1 Reply Last reply
      0
      • J Jorgen Andersson

        That's why you need to have an index on the id. (or any unique column or combination of columns) The index is already sorted per definition. So the WHERE id > @PreviousMaxID just walks down the b-tree to the right id and starts counting leafnodes until it reaches @PageSize. I don't know how AWS Aurora is organized, but if your table is clustered, you don't even need to lookup the pages and Bob's your uncle.

        Wrong is evil and must be defeated. - Jeff Ello

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

        I do not believe that is how that works. The primary key is indexed. However indexing is a btree and based on a hash. I presume natural ordering on the index would be to walk the btree. But, again, that would be based on the hash. In contrast "id > previous" is based on the value. I do not have access to the hashing algorithm and even if I used "hash(id) > hash(previous)" then it would end up doing a table scan (or at least an index scan) which would not help at all.

        J 1 Reply Last reply
        0
        • J jschell

          I do not believe that is how that works. The primary key is indexed. However indexing is a btree and based on a hash. I presume natural ordering on the index would be to walk the btree. But, again, that would be based on the hash. In contrast "id > previous" is based on the value. I do not have access to the hashing algorithm and even if I used "hash(id) > hash(previous)" then it would end up doing a table scan (or at least an index scan) which would not help at all.

          J Offline
          J Offline
          Jorgen Andersson
          wrote on last edited by
          #14

          B-tree is not hash based. MySQL DOES support[^] hash-based indexing, but that is not supported on neither MyISAM nor InnoDb. Only for Memory storage engine and NDB-clusters. And then you still need to choose between b-tree OR hash-based index. Hash-based indexes are obviously NOT ordered. I don't know anything about Amazons databases, so whether your index is hash-based or not is something you need to check. In my very personal opinion, the only reason to use a hash-based index instead of b-tree is if your data doesn't have any kind of ordering to it, like GUIDs for example. <edit>Curiosity took over, I wondered why your RefID was char(22), and it seems like a base64 encoding of GUIDs use exactly 22 characters.</edit>

          Wrong is evil and must be defeated. - Jeff Ello

          J 1 Reply Last reply
          0
          • J jschell

            Mycroft Holmes wrote:

            oh that is ugly - the 1,2 - 2,1 is going to cost you.

            Yep - not my design.

            Mycroft Holmes wrote:

            Can you do it in a couple of steps, inner join on the 2 layouts and eliminate them from the process,

            I suspect that join between the two tables will return on the order of a billion rows. Either because there are very few rows that are not matched or there are zero. I am only expecting the first because with legacy data orphans might occur.

            Mycroft Holmes wrote:

            possibly even move the non matching records

            I have to find them first. Once I find them I don't consider the analysis to be a problem. Actually for those that do not match I consider it likely they are orphans.

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

            Split it into groups by taking the first 1 or 2 characters, process each set independently. Getting desperate here as I'm running out of ideas.

            Never underestimate the power of human stupidity RAH

            J 1 Reply Last reply
            0
            • J Jorgen Andersson

              B-tree is not hash based. MySQL DOES support[^] hash-based indexing, but that is not supported on neither MyISAM nor InnoDb. Only for Memory storage engine and NDB-clusters. And then you still need to choose between b-tree OR hash-based index. Hash-based indexes are obviously NOT ordered. I don't know anything about Amazons databases, so whether your index is hash-based or not is something you need to check. In my very personal opinion, the only reason to use a hash-based index instead of b-tree is if your data doesn't have any kind of ordering to it, like GUIDs for example. <edit>Curiosity took over, I wondered why your RefID was char(22), and it seems like a base64 encoding of GUIDs use exactly 22 characters.</edit>

              Wrong is evil and must be defeated. - Jeff Ello

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

              Jörgen Andersson wrote:

              B-tree is not hash based.

              Ok. I stand corrected. So that should work.

              Jörgen Andersson wrote:

              I don't know anything about Amazons databases

              They do not expose the underlying implementation. But it should be a binary equivalent so your point should hold.

              Jörgen Andersson wrote:

              and it seems like a base64 encoding of GUIDs use exactly 22 characters

              Yes I believe that is correct. Not my design but I believe something I have looked at in just the last day would support that.

              J 1 Reply Last reply
              0
              • M Mycroft Holmes

                Split it into groups by taking the first 1 or 2 characters, process each set independently. Getting desperate here as I'm running out of ideas.

                Never underestimate the power of human stupidity RAH

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

                Also an interesting idea. For base 64 encoding that would give approximately 244000 per query(2 characters0 and, per the other comment, it should be fast enough to use that a page. The only limitation there would be if the values were not uniformly distributed.

                M J 2 Replies Last reply
                0
                • J jschell

                  Also an interesting idea. For base 64 encoding that would give approximately 244000 per query(2 characters0 and, per the other comment, it should be fast enough to use that a page. The only limitation there would be if the values were not uniformly distributed.

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

                  jschell wrote:

                  if the values were not uniformly distributed

                  Uhm I would presume the fields are indexed and physical location would be irrelevant.

                  Never underestimate the power of human stupidity RAH

                  1 Reply Last reply
                  0
                  • J jschell

                    Also an interesting idea. For base 64 encoding that would give approximately 244000 per query(2 characters0 and, per the other comment, it should be fast enough to use that a page. The only limitation there would be if the values were not uniformly distributed.

                    J Offline
                    J Offline
                    Jorgen Andersson
                    wrote on last edited by
                    #19

                    It's not uniformly distributed per definition, but the first half of a guid is the time part, and it's stored in reverse order of significance, so for this purpose it could probably be considered as uniformly distributed.

                    Wrong is evil and must be defeated. - Jeff Ello

                    J 1 Reply Last reply
                    0
                    • J jschell

                      Jörgen Andersson wrote:

                      B-tree is not hash based.

                      Ok. I stand corrected. So that should work.

                      Jörgen Andersson wrote:

                      I don't know anything about Amazons databases

                      They do not expose the underlying implementation. But it should be a binary equivalent so your point should hold.

                      Jörgen Andersson wrote:

                      and it seems like a base64 encoding of GUIDs use exactly 22 characters

                      Yes I believe that is correct. Not my design but I believe something I have looked at in just the last day would support that.

                      J Offline
                      J Offline
                      Jorgen Andersson
                      wrote on last edited by
                      #20

                      If it's a btree index it should work. But if it is a hash index, I really don't have a solution. Except adding a btree index on the table. Hash indexes are faster for lookups, but totally useless for ranges.

                      Wrong is evil and must be defeated. - Jeff Ello

                      1 Reply Last reply
                      0
                      • J Jorgen Andersson

                        It's not uniformly distributed per definition, but the first half of a guid is the time part, and it's stored in reverse order of significance, so for this purpose it could probably be considered as uniformly distributed.

                        Wrong is evil and must be defeated. - Jeff Ello

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

                        For clarification on that the value is actually based on the UUID from java. And that UUID would seem to have a uniform distribution because the layout is not strictly ordered by time - the UUID uses the minor time (probably seconds/millis) as the most significant part.

                        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