Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6990405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:20:43+00:00 2026-05-27T19:20:43+00:00

The situation that I am facing is that I am trying to work the

  • 0

The situation that I am facing is that I am trying to work the best way (in terms of memory storage usage) to represent the inventory stock held by different stores at different points in time. The setup is as follows:

Table: Stores

A table which is a list of the different stores:

  • Store Id (PK)
  • Store Name
  • … other details

Table: Stock

  • Stock Id (PK)
  • Stock Name
  • … other details

Table: Store Stock Holdings

  • Store Id
  • Stock Id
  • Date
  • Quantity

(Store Id, Stock Id and Date act as a joint primary key, with Store Id and Stock Id as foreign keys)

Alternatively I thought to store the stock holdings as a json string:

Table: Store Stock Holdings

  • Store Id
  • Date
  • Stock Holdings

So for example let’s say store 1 has 50 lemons(code = 1), 100 oranges(code =2), and 20 mangos(=3) on the Jan 1 2011, then the three setups would represent it as:

Option 1:

Store Id, Stock Id, Date, Quantity

1 , 1, 2011-01-01, 50
1 , 2, 2011-01-01, 100
1 , 3, 2011-01-01, 20

Option 2:

Store Id, Date, Stock Holdings

1 , 1, 2011-01-01, \{1,50;2,100;3,20\}

Option 3:

Would be to reduce the replication of storing the dates in Option 1 by splitting it into two tables as follows:

Index, Store Id, Date

1, 1, 2011-01-01

Index, Stock Id, Stock Holdings

1, 1, 50
1, 2, 100
1, 3, 20

So the questions are:

  1. What would be my speed and storage considerations for the different implementations. My thinking is Option 3 and Option 2 are likely the better choice as the date information isn’t replicated.

  2. For Option 2, is the memory storing the JSON string allocated dynamically? What I mean by this is the JSON string could be potentially quite large and as a result one would need to allow for it. Would then a new entry take up the total allocation or only the required amount of memory based on the JSON string? My understanding is that using varchar will allocate the memory dynamically. Would you suggest using varchar?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:20:44+00:00Added an answer on May 27, 2026 at 7:20 pm

    MySQL is a relational database management system, so it is designed to operate on normalized relational data.

    This means that it cannot efficiently index JSON strings: you won’t be able to say, search by stockId efficiently, run aggregate queries grouping by stock etc.

    The only thing you’ll be able to do fast is to retrieve all store contents (whether you need it or not) given the store id.

    So option 2 is only viable if you are using MySQL as a pure key-value storage. There are many systems on the market which are better suited for that purpose.

    As for choosing between option 1 and option 3, the latter just replaces a natural composite key (storeId, date) with a surrogate one (index).

    An integer is shorter in size than INT + DATE combination, so there may be edge cases when this option is better (especially if you have few dates with really many entries on each date and you don’t need to query all stores or all dates given a stock). However, keeping everything in one table lets you create composite indexes on any combination of storeId, stockId and date which may be crucial for performance.

    To help you choose between the two, we need to know what kind of queries will you be running, but option 1 (with storeId, stockId and date in one table) would be definitely the model of choise.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a situation that I solved in the following way: //cube_potentials is float8
I am facing a situation that I have problem understanding... I am writing a
This is a situation I'm generally facing while writing SQL queries. I think that
Here is the situation that I'm facing: I have two tables A and B.
I am facing some odd situation that when I select/deselect the features in the
Now I am facing a situation that I'm building a website without mysql or
I would like to explain the situation that I am facing. By default iPhone
I have an interesting situation that EMF forced me into: abstract class AbstractDog{ ...
I have a situation that requires redirecting users who are already logged in away
I’m in the situation that I have to design and implement a rather big

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.