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 7602833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:30:46+00:00 2026-05-30T23:30:46+00:00

I think it is necessary to de-normaize database for user notifications. For example, when

  • 0

I think it is necessary to de-normaize database for user notifications. For example, when flagging a post (which should be considered by user), we add a column of flag ENUM('yes', 'no') (or status column). Finding flagged events for a user can be by counting with WHERE clause of user_id='XX' AND flag='yes'.

This normalized structure is fine; but what if we have different types of notifications; e.g. flags for posts, comments, photos … This means that we need to count several tables when the user is just visiting his profile page. This is more serious for a cross-project like stackexchange, as we get notifications for different sites.

I think de-normalization can help to add notification columns to the user table as

post_flags tinyint(3),
comment_flags tinyint(3),
photo_flags tinyint(3),

In this case, we need to run an additional write query for updating user flag columns on every corresponding actions. For example, when flagging a post: UPDATE users SET post_flags=post_flags+1 WHERE user_id='XX'. My concern is to ensure execution of the latter query to avoid any mismatch between this number and the count of flagged posts; but I think it can be secured by TRANSACTION.

In this way, we get all notification with one query for frequently visited profile pages.

Am I on the right track? or another tricky approach is common for this purpose?

  • 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-30T23:30:47+00:00Added an answer on May 30, 2026 at 11:30 pm

    You’d probably be better off with a table of user notifications.

    create table user_notifications (
      user_id integer primary key, -- ? references users, not shown
      post_flags unsigned tinyint(3) not null default 0,
      comment_flags unsigned tinyint(3) not null default 0,
      photo_flags unsigned tinyint(3) not null default 0
    );
    

    A separate, narrower table is both logical and (probably) faster. Unsigned for flags, because negative numbers there make no sense, and MySQL doesn’t enforce CHECK constraints.

    As far as normalization goes, user_notifications is in 5NF.

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

Sidebar

Related Questions

Think about the following: Your ISP offers you a dynamic ip-address (for example 123.123.123.123).
I think this is specific to IE 6.0 but... In JavaScript I add a
my site has now become sufficiently large for me to think it's necessary to
I'm designing a database application which stores simple contact information (First/Last Name etc.) and
Do you think it is necessary to mark id fields with insertable = false
Can somebody tell me why compiler thinks that break is necessary after yield return
and why does Implementation ID necessary in ECOM? UID3 is not enough? thank you.
Think: tiling my emacs window with eshells, a la xmonad. Is this possible? I
I think the file that is produced is an .asm file, any idea how
I think most people know how to do this via the GUI (right click

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.