Results 1 to 12 of 12
  1. #1
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142

    Flagging Archived Data

    Is this a good idea or bad idea:

    You have a chain of related tables. At the "root" table you have a bool flag [is_archived]. If a [root] record is archived then all the related children and grandchildren and so on would also be considered archived.

    The idea is the child tables also have an [is_archived] flag, and these flags are part of the foreign key relationships. The referential integrity is set up to 'cascade updated related fields'


    • So if you tick a root record as archived then the db will automatically update all the related records at each child, grandchild, etc, as archived. this could be thousands of records per each root record. No need for (multiple) update queries
    • Queries against the child tables can now be simplified, you don't have to join related tables or do lookups to figure out what records don't belong to archived root records. I assume this could potentially improve performance substantially
    • this is de-normalizing
    • you cant archive just parts of the data within a root record's family or related data, it's all or nothing


    Thoughts?

    Click image for larger version. 

Name:	3.png 
Views:	27 
Size:	32.4 KB 
ID:	50416

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    IMO a boolean field is not of much use for this. I'd use a date field. If it's null, it's current. Anything with a date would not be returned in a query if you create it that way. As for the related records, there'd be no parent record in the main data returned by the query (if you set criteria to be null), therefore no child records would be returned anyway. Having archive field in the child tables is redundant and only adds an unnecessary level of complexity.
    Plus, a date field tells you when the record was archived as well. A checkbox doesn't do that.
    Last edited by Micron; 06-26-2023 at 09:06 AM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Also, this would preclude the possibility of a subwidget being used for more than one widget. I don't know if that fits your actual scenario, but wanted to mention it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Quote Originally Posted by Micron View Post
    ... As for the related records, there'd be no parent record in the main data returned by the query (if you set criteria to be null), therefore no child records would be returned anyway.
    My point is it would now be possible to run aggregate queries on child tables without needing to first join parent tables, or an entire lineage of tables, to filter out archived data. (apologies, I probably should have mentioned aggregate queries in the op)

    Let's imagine that a child table might have upwards of a million records. Is it faster for ms access to filter by joining (multiple) tables or filter by a flag in the table itself (or "is null" if appropriate)? I don't know, I should probably put together some tests.

    Having archive field in the child tables is redundant
    agreed!

    and only adds an unnecessary level of complexity.
    maybe not entirely unnecessary if it means a performance boost?



    Quote Originally Posted by pbaldy View Post
    Also, this would preclude the possibility of a subwidget being used for more than one widget. I don't know if that fits your actual scenario, but wanted to mention it.
    That's a great point to keep in mind, thank you. It goes along with my final point that it's all or nothing up and down the chain of related tables.

  5. #5
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Quote Originally Posted by Micron View Post
    ...only adds an unnecessary level of complexity...
    But does it really? with 'cascade update related fields' the db engine takes care of everything. After you set up the relationship you can forget about it... i think. lol

    It certainly adds bloat with extra indexes and duplicated data.

  6. #6
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    I haven't tested this, but I suspect a join is very efficient.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    You're right - it's denormalized - in the sense that you have repeating data. Whether or not it is a good idea or not I can't say but as noted, it's a bad idea if an archived sub is needed on another parent. I can say that I've never needed to be concerned with running queries on child tables (as much as I can recall) so there's that. I am also of the understanding that joins are very efficient. It seems to me the only upside to this is simpler queries, which in your case it seems there's nothing to gain with respect to performance, but only in not having to take the time to do it right (if I can put it that way). I guess time will tell.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    or filter by a flag in the table itself (or "is null" if appropriate)?
    null or not null would be better because you can exclude nulls from an index - so the index is shorter and faster because the logic is it is in the index or it isn’t.

    Using a yes/no field it will be populated with 0’s and -1’s so even tho’ indexing is fast the standard recommendation is little point in applying indexes to fields with a limited range of values - it would effectively be the equivalent of a sequential search

  9. #9
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Interesting point about nulls and indexes.

    Ive read that there isn't much to gain from indexing bools but I have seen reports on massive performance gains from doing it anyway. It just depends on the circumstances it seems. https://stackoverflow.com/questions/...-boolean-field

    This might be beside the point but for the record I use faux bool fields in access per Allen Browne recommendations. That's an integer fields with a validation rule of "-1 or 0"

  10. #10
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Update: I threw together some test data of about a million rows. From my testing the performance difference is minimal to almost non existent between filtering by joins vs filtering by field within table. I also am not seeing a performance difference between True/False vs Is Null/ Is Not Null.

  11. #11
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    From my testing the performance difference is minimal to almost non existent between filtering by joins vs filtering by field
    So where is the gain by not normalizing and instead, using cascade updates vs queries with tables you otherwise don't need - or is there any? While this may work for your case, the fact that archived sub data cannot be used by a different parent (or grandparent as the case may be) makes it a non-starter for me. Imagine a scenario where a sub component is no longer specific to a particular parent component because a new parent makes it so, yet the child has been archived. Or the parent is redesigned to the point where the updated parent becomes a new part and the old version info is archived and the information kept. Now the link is broken between the archived version and its child because the parent is archived and the child is not.

    I think that's all I can offer as commentary to the original question.
    Last edited by Micron; 06-27-2023 at 01:35 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  12. #12
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Quote Originally Posted by Micron View Post
    So where is the gain by not normalizing and instead, using cascade updates vs queries with tables you otherwise don't need - or is there any?
    From post 10, as far as I can tell if there's any performance gain at all it's negligible

    (I'm not trying to advocate for this method, was just exploring an idea)

Please reply to this thread with any new information or opinions.

Similar Threads

  1. New record error, due to archived data??
    By kissthis66 in forum Access
    Replies: 1
    Last Post: 10-06-2020, 02:38 PM
  2. Help with query for archived data..
    By MrOhhmy in forum Queries
    Replies: 15
    Last Post: 05-01-2019, 04:49 PM
  3. Replies: 4
    Last Post: 12-22-2017, 03:44 PM
  4. Replies: 2
    Last Post: 07-12-2016, 12:11 PM
  5. Automatic Flagging
    By terricritch in forum Access
    Replies: 4
    Last Post: 09-14-2010, 06:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums