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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:09:16+00:00 2026-05-23T11:09:16+00:00

Can anyone instantly see a problem or bottleneck in the schema below? Reads are

  • 0

Can anyone instantly see a problem or bottleneck in the schema below? Reads are 90% of the operations, but I’d like to know if I’m shooting myself in the foot anywhere on the writes either.

The Proposition

Each object (row in another table) can be related to other objects. There can only ever be one record for each relation pair (pairs are directionally sensitive, so X to Y can co-exist with Y to X).

+-------+---------------------+------+-----+---------+----------------+
| Field | Type                | Null | Key | Default | Extra          |
+-------+---------------------+------+-----+---------+----------------+
| a_id  | bigint(20) unsigned | NO   | PRI | NULL    |                |
| b_id  | bigint(20) unsigned | NO   | PRI | NULL    |                | 
+-------+---------------------+------+-----+---------+----------------+

A typical request will be to get all related objects (for a given object A):

SELECT * FROM objects INNER JOIN relations ON id = b_id WHERE a_id = A

Relations are managed using a simple checkbox array in the UI. To save relations, I’d calculate the difference between checked/non-checked in the current set (objects will be paged in the UI), and then just insert/delete accordingly;

DELETE FROM relations WHERE a_id = A AND b_id IN(B,C)

# if these relations already exist, will fail silently
INSERT IGNORE INTO relations (a_id, b_id) VALUES (A,D), (A,E)

I may also need to query reverse-relations, using just b_id for selects – since it’s not left of the index, will it be used at all? And if not, will adding a separate index on it induce significant overhead for writes?

  • 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-23T11:09:16+00:00Added an answer on May 23, 2026 at 11:09 am

    The advantage of adding a second index on b_id will outweigh any overhead for writes, since without the index, it will need to do a full table scan to filter by b_id.

    As far as making the index on just b_id or b_id, a_id depends on the table engine, Since InnoDB stores the primary key in the secondary indexes, however MyISAM does not.

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

Sidebar

Related Questions

Can anyone tell me how I can display a status message like 12 seconds
Suspect I am doing something stupid, but I can't see for the wood for
Does anyone know how this is rendered: http://blogs.oracle.com/realneel/resource/open_table_hash_walk.svg I really like this horizontal visualization
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of
Can anyone recommend a good library for generating an audio file, such as mp3,
Can anyone recommend some good resources that highlight the differences between Oracle and the
Can anyone point me to a good resource (or throw me a clue) to
Can anyone recommend a good binary XML format? It's for a JavaME application, so
Can anyone recommend software or a .NET library that will check for bounced emails
Can anyone point me in the right direction on this. From reading the FAQs

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.