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. Table Design Suggestion

Table Design Suggestion

Scheduled Pinned Locked Moved Database
cssdatabasedesignperformanceannouncement
7 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.
  • M Offline
    M Offline
    Manish K Agarwal
    wrote on last edited by
    #1

    I have to maintain some metadata lists in DB, I have 2 options to design underlying simple table, 1st:

    NAME VALUE

    dept HR
    dept fin
    role engineer
    role designer

    UNIQUE CONSTRAINT (NAME, VALUE) and some other columns like auto generated ID, etc. 2nd:

    NAME VALUE_JSON_CLOB

    dept {["HR", "fin"]}
    role {["engineer", "designer"}]

    UNIQUE CONSTRAINT (NAME) and some other columns like auto generated ID, etc. There is no DELETE operation, only SELECT and INSERT/UPDATE. In first advantage is only INSERT is required but SELECT (fetch all values for a given NAME) will be slow. In second SELECT will be fast but UPDATE will be slow. By considering there could be 1000s of such lists with 1000s for possible values in the system with frequent SELECTs and less INSERTs, which TABLE design will be good in terms of performance. Thanks in advance.

    N Richard DeemingR M 3 Replies Last reply
    0
    • M Manish K Agarwal

      I have to maintain some metadata lists in DB, I have 2 options to design underlying simple table, 1st:

      NAME VALUE

      dept HR
      dept fin
      role engineer
      role designer

      UNIQUE CONSTRAINT (NAME, VALUE) and some other columns like auto generated ID, etc. 2nd:

      NAME VALUE_JSON_CLOB

      dept {["HR", "fin"]}
      role {["engineer", "designer"}]

      UNIQUE CONSTRAINT (NAME) and some other columns like auto generated ID, etc. There is no DELETE operation, only SELECT and INSERT/UPDATE. In first advantage is only INSERT is required but SELECT (fetch all values for a given NAME) will be slow. In second SELECT will be fast but UPDATE will be slow. By considering there could be 1000s of such lists with 1000s for possible values in the system with frequent SELECTs and less INSERTs, which TABLE design will be good in terms of performance. Thanks in advance.

      N Offline
      N Offline
      Nathan Minier
      wrote on last edited by
      #2

      Performance is a meaningless metric unless we know what your use case is. Also, the second is more like an object store, and would do better in a non-relational (NoSQL) system.

      "There are three kinds of lies: lies, damned lies and statistics." - Benjamin Disraeli

      M 1 Reply Last reply
      0
      • M Manish K Agarwal

        I have to maintain some metadata lists in DB, I have 2 options to design underlying simple table, 1st:

        NAME VALUE

        dept HR
        dept fin
        role engineer
        role designer

        UNIQUE CONSTRAINT (NAME, VALUE) and some other columns like auto generated ID, etc. 2nd:

        NAME VALUE_JSON_CLOB

        dept {["HR", "fin"]}
        role {["engineer", "designer"}]

        UNIQUE CONSTRAINT (NAME) and some other columns like auto generated ID, etc. There is no DELETE operation, only SELECT and INSERT/UPDATE. In first advantage is only INSERT is required but SELECT (fetch all values for a given NAME) will be slow. In second SELECT will be fast but UPDATE will be slow. By considering there could be 1000s of such lists with 1000s for possible values in the system with frequent SELECTs and less INSERTs, which TABLE design will be good in terms of performance. Thanks in advance.

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #3

        I'd immediately rule out the second option. You should always try to avoid storing multiple values in a single column. Assuming the data is meant to be a set of look-ups for other records, I'd also try avoid the first option. Put each list in its own table - Departments, Roles, etc. That way, you'll be able to define foreign key relationships from the tables that reference them.


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        M 1 Reply Last reply
        0
        • M Manish K Agarwal

          I have to maintain some metadata lists in DB, I have 2 options to design underlying simple table, 1st:

          NAME VALUE

          dept HR
          dept fin
          role engineer
          role designer

          UNIQUE CONSTRAINT (NAME, VALUE) and some other columns like auto generated ID, etc. 2nd:

          NAME VALUE_JSON_CLOB

          dept {["HR", "fin"]}
          role {["engineer", "designer"}]

          UNIQUE CONSTRAINT (NAME) and some other columns like auto generated ID, etc. There is no DELETE operation, only SELECT and INSERT/UPDATE. In first advantage is only INSERT is required but SELECT (fetch all values for a given NAME) will be slow. In second SELECT will be fast but UPDATE will be slow. By considering there could be 1000s of such lists with 1000s for possible values in the system with frequent SELECTs and less INSERTs, which TABLE design will be good in terms of performance. Thanks in advance.

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

          Listen to Richard, I recently got told that us old folks did not know the modern way of doing things the "architect" want to put all the lookup data into 1 table. He ended up with 5 table and a dogs breakfast of different relationships maintained in the business layer and not the database where I wanted it. Use 1 table for each different type of lookup data, use a primary key (not a code) and foreign keys.

          Never underestimate the power of human stupidity RAH

          1 Reply Last reply
          0
          • N Nathan Minier

            Performance is a meaningless metric unless we know what your use case is. Also, the second is more like an object store, and would do better in a non-relational (NoSQL) system.

            "There are three kinds of lies: lies, damned lies and statistics." - Benjamin Disraeli

            M Offline
            M Offline
            Manish K Agarwal
            wrote on last edited by
            #5

            As described above as well: There is no DELETE operation, only SELECT and INSERT/UPDATE. Also every time I want to select all possible values for given NAME. This is a kind of reference list to fill the autocomplete suggestions on UI. Hence fetch will be always all values and INSERT new only one value at a time.

            N 1 Reply Last reply
            0
            • Richard DeemingR Richard Deeming

              I'd immediately rule out the second option. You should always try to avoid storing multiple values in a single column. Assuming the data is meant to be a set of look-ups for other records, I'd also try avoid the first option. Put each list in its own table - Departments, Roles, etc. That way, you'll be able to define foreign key relationships from the tables that reference them.


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              M Offline
              M Offline
              Manish K Agarwal
              wrote on last edited by
              #6

              It is a complex system where I don't know upfront what all possible reference list may exist in the runtime environment. Also, these value will never be referenced from any other table or column. A kind of auto-suggest list and user is always free to choose new value if not like any of the suggestions.

              1 Reply Last reply
              0
              • M Manish K Agarwal

                As described above as well: There is no DELETE operation, only SELECT and INSERT/UPDATE. Also every time I want to select all possible values for given NAME. This is a kind of reference list to fill the autocomplete suggestions on UI. Hence fetch will be always all values and INSERT new only one value at a time.

                N Offline
                N Offline
                Nathan Minier
                wrote on last edited by
                #7

                Manish K. Agarwal wrote:

                Also every time I want to select all possible values for given NAME.

                Not exactly what you said above, to be fair. It also doesn't say whether this is native or web-based, which has a relevant impact on performance of the system as a whole. If writes are rare in either case, you'll see better SELECT performance out of option 2 for one simple reason: assuming that you index the key, when it's found the appropriate key, it's done and will stop searching the table. If you're in a web environment, you have the added benefit of being able to send it straight down the pipe with no serialization/deserialization required. If all your model requires is selection speed, option 2 is the way to go. Option 2 is definitely not write friendly, though, nor can you use it to relate data down the road on the database level. If these are likely or even possible considerations, you might want to go with option 1.

                "There are three kinds of lies: lies, damned lies and statistics." - Benjamin Disraeli

                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