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

  • Home
  • SEARCH
  • 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 9152923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:10:21+00:00 2026-06-17T12:10:21+00:00

I have a private messaging system for my users that I’ve created in php

  • 0

I have a private messaging system for my users that I’ve created in php with a mysql backend. The system deletes old messages but generally holds over 500,000 messages. Currently all of the data is included in one table:

message_table
    message_id (int 11)
    message_from_id (int 11)
    message_to_id (int 11)
    message_timestamp (int 11)
    message_subject (varchar 50)
    message_text (text)

The majority of messages are very short so I’m considering changing the system to:

message_table
    message_id (int 11)
    message_from_id (int 11)
    message_to_id (int 11)
    message_timestamp (int 11)
    message_subject (varchar 50)
    message_short_body (varchar 50)
    message_text_id (int 11)

text_table
    text_id (int 11)
    text_body (text)

Then if a short message is entered it will be entered under ‘message_short_body’ and if longer will be added to ‘text_table’ and the ‘text_id’ stored as ‘message_text_id’. When messages are access I would then have something like:

SELECT * FROM message_table LEFT JOIN text_table ON text_table.text_id = message_table.message_text_id IF message_table.message_text_id != 0 WHERE message_table.message_to_id = $user_id

I added “IF message_table.message_text_id != 0” and don’t know if something like that is possible.

As a general rule is it possible to tell if this would reduce the size of the database / speed up queries ?

  • 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-06-17T12:10:22+00:00Added an answer on June 17, 2026 at 12:10 pm

    I added “IF message_table.message_text_id != 0” and don’t know if something like that is possible.

    Unless there actually is a row with text_id = 0 in your text_table, there is no need to do this. Simply omit the IF and use the following query:

    SELECT IFNULL(text_table.text_body, message_table.message_short_body) AS body,
           …
    FROM message_table
    LEFT JOIN text_table ON text_table.text_id = message_table.message_text_id
    WHERE message_table.message_to_id = $user_id
    

    In terms of performance, it might be that the engine can optimize things more efficiently if you add your condition to the join conditions:

    SELECT IFNULL(text_table.text_body, message_table.message_short_body) AS body,
           …
    FROM message_table
    LEFT JOIN text_table ON text_table.text_id = message_table.message_text_id
                        AND message_table.message_text_id != 0
    WHERE message_table.message_to_id = $user_id
    

    You could also try an approach using a subquery:

    SELECT IF(message_text_id = 0, message_short_body, (
      SELECT text_table.message_short_body
      FROM text_table
      WHERE text_table.text_id = message_table.message_text_id)) AS body,
           …
    FROM message_table
    WHERE message_table.message_to_id = $user_id
    

    This has the benefit of not executing the search in text_table if none is required, but the drawback of performing a separate query for each case with a long message. I would expect the above queries to be superior, but I’m not sure.

    As a general rule is it possible to tell if this would reduce the size of the database / speed up queries ?

    You’ll have to benchmark, as it depends on the use case. If most of your queries retrieve data from the fields other than the text, then the smaller table will make those queries faster, yielding a performance gain. If, on the other hand, you usually want the body along withe the rest of the message, then you’ll likely end up with worse performance.

    You should also use benchmarks to distinguish between the different alternatives described above.

    In terms of size of the database, you’ll likely see an increase: the storage requirements for the text data are about the same, but the indices for the extra table will cost you.

    I guess if this were my schema, I’d drop the message_text_id and instead have primary key of the text_table match that of the message_table. I.e. each key occurs either only in the message table or in both tables, and rows with the same key belong together. Whether or not the message is in the other table could be encoded by setting message_table.message_short_body to NULL in these cases.

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

Sidebar

Related Questions

I have a Private messaging system using PHP and mySQL with notification. The database
Take facebook's private messaging system where you have to keep track of sender and
Backgroun: I'm trying to build a private messaging system in Mysql with conv view.
I'm designing a C#/NHibernate website that features a private messaging system. I would like
I have a private messaging system and would like to have about 4-5 links
I have just had something created similar to the way private messages works on
I am building a simple messaging system with Rails3 that allows users to send
im trying to create a simple private messaging system i have a nested route
Here's the c# code that I have: private double get806Fees (Loan loan) { Loan.Fee.Items
Why can NHibernate create a proxy for classes with properties that have private setters

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.