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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:42:19+00:00 2026-05-29T10:42:19+00:00

I have a table of messages Key – UserId, MsgIndex C1…Cn – some data

  • 0

I have a table of messages

Key - UserId, MsgIndex
C1...Cn - some data columns
Cn+1 - Date, when message has been added to the table.

Question is the best practice to do with client…

Client ask server for new messages…

There are 2 options to do it:

  1. check for messages with index > lastRxMsgIndex (client will save the last msg index received)
  2. check for messages with date > lastRxMsgDate (client will save the last rx msg date- server will give it to him when getting msg results)

Which is better and faster…

Keeping date/TS or index is the same, common sense says to keep date/TS but it is same for msg index.

MsgIndex is in the table primary key so should it be faster that searching on dates (when user will have many messages…)

Which is the best way?

Thanks
Yoav

  • 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-29T10:42:20+00:00Added an answer on May 29, 2026 at 10:42 am

    First regarding performance: you could add an index to your date column to improve the performance of searches by date. You will most likely want to also include the user_id in the index. You could for example use a combined index on (user_id, id) or (user_id, date) so that individual users can quickly find the messages they own without the server having to scan through other users’ messages too.

    Regarding functionality: One potential issue with using the datetime as a key is that timestamps are not in general unique. It’s possible (but unlikely) that if you search based on date you’ll miss a message. Here’s an example scenario demonstrating the problem:


    At 16:01:04.312 the table contains two messages:

    id    date                  message
    1     2012-02-10 14:23:54   foo
    2     2012-02-10 16:01:04   bar
    

    The client already has received row 1 previously and now requests and receives the latest row:

    SELECT * FROM your_table WHERE date > '2012-02-10 14:23:54'
    (1 row)
    

    Then at 16:01:04.420 a new row comes into the database with the same timestamp:

    id    date                  message
    1     2012-02-10 14:23:54   foo
    2     2012-02-10 16:01:04   bar
    3     2012-02-10 16:01:04   baz
    

    Client requests latest row but doesn’t get it:

    SELECT * FROM your_table WHERE date > '2012-02-10 16:01:04'
    (0 rows)
    

    Another issue is if the server’s time is adjusted backwards. This could cause later messages to be inserted with an earlier timestamp. These messages will also be missed if you use the date to find the newest messages. It may be better to use the id instead to avoid these potential problems.

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

Sidebar

Related Questions

I have a messages table with the following columns: id (primary Key) username timestamp
I have a table Messages with columns ID (primary key, autoincrement) and Content (text).
I have a table row that has the error message in it. <tr runat=server
I have table messages with two foreign key: user_id_from and user_id_to . I need
I have a 'message' table, where users send and receive messages, pretty straight forward.
I have a table that stores messages from one user to another. messages(user_id,friend_id,message,created_date). My
well i have this messages table with sample values like these: msg_id recipient_id read
I have an Oracle table which contains event log messages for an application. We
i have a stack of messages in database table. i want to send these
I have a Message table and a User table. Both are in separate databases.

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.