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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:03:47+00:00 2026-05-26T15:03:47+00:00

I have to work on CRON which will be sending email to subscriber weekly

  • 0

I have to work on CRON which will be sending email to subscriber weekly on the day they get subscribed. For example if user A subscribed on Thursday and user B subscribed on Wednesday then user A will get mail on every Thursday and user B on every Wednesday.

Now my approach will be following:

1- First get the day of the week of current(TODAY) date and assign in a variable

2- Running the SELECT query and fetch all subscriber IDs who’s subscription day’s is similar to the day of Today’s Date. I am planning to use MYSQL’s dayofweek() to extract day from Week,

3- Once getting all IDs then send last 7 day activities to those subscribers via email.

Thing thing which is making me a bit puzzled is DAYOFWEEK() function which column based and looks costly. What alternative would you suggest?(Assuming the table would have lots of data)

  • 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-26T15:03:47+00:00Added an answer on May 26, 2026 at 3:03 pm

    Per-row functions rarely scale well as the database table grows.

    The first thing you should do is make sure there’s actually a performance problem to solve. Always start with third normal form and regress only if you find such a problem, otherwise your effort is wasted. It may be that the speed is not that bad in which case stick with 3NF.


    If it turns out there is a performance problem, one way to solve it is to add and indexed column called weekday that will hold the day of the week the user subscribed.

    This is technically breaking 3NF since that attribute is dependent on the date of subscription which is unlikely to be part of the key. It may also come to disagree with that subscription date if you update one or the other independently.

    But you can mitigate the problem by having an insert/update trigger which forces the weekday column to agree with the subscription date, ensuring that they never disagree.

    Then your query simply becomes something like:

    dow = Now.dayOfWeek()
    rowSet = executeQuery ("select sub_id from subscribers where weekday = ?", dow)
    

    and then processing each of those subscribers (or as one big honkin’ query if you wish).

    The fact that you’re not having to retrieve every row to do a getWeekDay (subscription_date) and filter the rows should massively improve the query speed.

    The vast majority of databases are read far more often than written and, by shifting the cost of the calculation to the insert/update, you effectively amortise that cost over all selects.

    Assuming your subscribers subscribe for more than a week (since you send out their stuff once a week), that will be more efficient than calculating on the select.

    And, although this takes up more space in your table (due to the extra column and index), have a look at the ratio of “My query isn’t fast enough” questions compared to “My database is too big” questions. The former far outweigh the latter.

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

Sidebar

Related Questions

I have to work with strings which may contain Lat/Long data, like this: $query
I have a bash script runned every day via cron. In this bash I
I have few bash scripts which are adding to cron jobs with specified timing,
In Team Foundation Server is there a way to have work items in one
I have to work on an old 1.3 JVM and I'm asked to create
I have to work on several VB6 legacy projects and despite some good VB6
I have to work on some code that's using generic lists to store a
I have to work with an API that uses a lot of by-reference parameters.
I have to work with a queryset, that is already filtered, eg. qs =
Sometimes I have to work on code that moves the computer clock forward. In

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.