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

  • Home
  • SEARCH
  • 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 1010917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:09:22+00:00 2026-05-16T09:09:22+00:00

No worries! It looks more complex than it actually is! Just get down to

  • 0

No worries! It looks more complex than it actually is! Just get down to the drinks!

TLDR-version: How to efficiently query and update entities having relationships to other entities?

Here’s an interesting data modeling scenario with two tables that has been puzzling me:

Entities { ID, Name, ScalarValue }

ComponentEntities { AggregateEntityID, ComponentEntityID, quantity }

AggregateEntityID and ComponentEntityID are foreign keys to the Entities table.

Give me the bloody example already

Drinks { ID, Name, Alcohol% }

DrinkIngredients { CocktailID, IngredientID, amount }

Drinks { 1, "Vodka", 40% }
Drinks { 2, "Tomato juice", 0% }
Drinks { 3, "Tabasco", 0% }
Drinks { 4, "Bloody mary", - }

DrinkIngredients { 4, 1, 0.2 } // Bloody mary has 0.2*Vodka
DrinkIngredients { 4, 2, 0.7 } // Bloody mary has 0.7*Tomato juice
DrinkIngredients { 4, 3, 0.1 } // Bloody mary has 0.1*Tabasco

If we wanted to get Bloody Mary’s alcohol contents, we would SELECT * FROM DrinkIngredients WHERE CocktailID == 4.

Pretty standard; nothing weird there. Lisa likes to make it a bit sweeter by adding some Passion to it:

Drinks { 6, "Passion", 13% }
Drinks { 7, "Bloody Mary Pink", - }

DrinkIngredients { 7, 4, 0.8 }  // Bloody Mary Pink has 0.8*Bloody Mary
DrinkIngredients { 7, 6, 0.2 }  // Bloody Mary Pink has 0.2*Passion

Lisa’s mum has been tasting these for so long that she believes she has found the ultimate blend between the two:

Drinks { 8, "Bloody Milf", - }
DrinkIngredients { 8, 4, 0.45 } // Bloody Milf has 0.45*Bloody Mary
DrinkIngredients { 8, 7, 0.55 } // Bloody Milf has 0.55*Bloody Mary Pink

Add couple more of these consists of levels and we have a deep relational recursion. The only restriction is that entity cannot consist of itself.

This seem to form a directed acyclic graph.

RDBMS: One way to “cache” the data would be to calculate relevant data and store it in the Entity itself (or perhaps in another table). In the example above, the alcohol content for Bloody Mary would calculated once when it’s created and stored in its Alcohol% field. In this case, updates become expensive because we have to update every drink (along with the whole dependency hierarchy) consisting of the updated one.

Questions

RDBMS: Is there a better way to get to the leaf values (drinks that don’t consist of other ones) than getting the “parent” drink until a leaf drink is reached?

Both, RDBMS and NoSQL, have a problem with this: one way or the other.

Bottom-line: is this even practical and feasible?

What I need is a counter-inception

alt text

  • 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-16T09:09:24+00:00Added an answer on May 16, 2026 at 9:09 am

    “RDBMS: Is there a better way to get to the leaf values (drinks that don’t consist of other ones) than getting the “parent” drink until a leaf drink is reached?”

    Don’t understand this. Drinks that don’t consist of other ones has nothing to do with recursion. It’s a simple EXCEPT or WHERE NOT EXISTS.

    And “getting to the leaf values” (given a parent) will inevitably require traversing the tree, regardless of the data structure (relational or hierarchical) used to model it, wouldn’t you think ?

    Both, RDBMS and NoSQL, have a problem with this: one way or the other.

    RDBMS don’t really have a problem with this. The problem was already identified a few decades ago (80’s or so), and was addressed by amending the relational algebra with a transitive closure operation, and a generalized version of it. SQL supports this through recursive queries, and as Frank said, at least all the big dogs all support recursive queries one way or the other.

    Bottom-line: is this even practical and feasible?”

    Writing recursive queries isn’t exactly trivial if you’ve never done it before. Does that make it “unpractical” ? I wouldn’t know.

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

Sidebar

Related Questions

During our initial development we haven't worried about scaling concerns, just getting the bare
I am in the processes of replacing the framework for a fairly complex business
I have Apache running on a public-facing Debian server, and am a bit worried
I'm working on a webservice + AJAX interface, and I'm worried about authentication. This
When beginning a new web project, i'm always a bit worried about removing pieces
I am writing refactoring a Silverlight program to consumes a portion of its existing
I'm trying to export classes from a DLL that contain objects such as std::vectors
I'm faced with a design decision that doesn't smell to me, but gives me
I am importing a feed into Tumblr and because of the formatting of the
I'm finding that the code that I write in my controllers is largely repetitive

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.