Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If we make the assumption that a ChildId always retains the same ParentId, then one option to consider is to add ParentId to Big_Table. If you are certain rows will only be added to these tables from application code you control (as opposed to, for example, someone with a database connection running INSERT statements themselves), you could keep a cache of the parent and child tables in memory and provide quick mapping of ChildId to ParentId when inserting into Big_Table. Then your sum/count query would be done entirely on Big_Table only. This denormalization of course will increase the size of Big_Table, but if that and application changes are tolerable this it is a viable option.</p> <p>Furthermore, if ParentId is the primary way of accessing rows in Big_Table (or the one with the greatest performance concerns), then you could consider partitioning Big_Table on ParentId.</p> <p>An entirely different approach would be to store the statistics you desire directly in Parent_Table, and either use triggers on Big_Table to keep them updated or, if you control all the database interaction in application code, use application logic to update the statistics as part of a Big_Table insert. You could do this in-transaction to ensure consistency, or if you are tolerant of some error, it could be done as an asynchronous statistics update, so that inserts on Big_Table can happen quickly, while statistics get updated in the background.</p> <p>As to handling additional levels of parents and children, you might need to choose between flexibility and efficiency. For instance, you might need to limit the depth of the tree you are willing to support in order to hard-code depth logic in order to improve performance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload