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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:14:46+00:00 2026-06-04T09:14:46+00:00

I am developing a HTML5 multiplayer game, where I have a m:n relation between

  • 0

I am developing a HTML5 multiplayer game, where I have a m:n relation between tables “keyword” and “model”, like the following image shows:

Database scheme

keyword.id and model.id are auto_increment unsigned int and keyword.keyword is an unique index.
For the sake of efficiency, I am searching for a way to manage the relation. The trivial way would be:

  • Check if keyword already exist
  • If yes: update timesCount and roundCount from model_has_keyword
  • If no: insert into keyword and insert into model_has_keyword

But with a growing number of users playing simultaneously, I’m afraid that the trivial way will become too slow. So what is the most efficient way to do this?

While searching on StackOverflow, I’ve stumpled upon two ideas, but I think they both don’t fit my needs.

  1. INSERT INTO table ON DUPLICATE KEY UPDATE col=val
    If INSERT INTO would be processed, I would need to trigger another INSERT INTO statement to insert into both tables keyword and model_has_keyword
  2. REPLACE statement: if I replace the record in table keyword, id is assigned the next auto-increment value, so that the reference for table model_has_keyword is lost.

As I’m not an expert, please correct me if I misunderstood something here.

  • 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-04T09:14:48+00:00Added an answer on June 4, 2026 at 9:14 am

    You need to check whether the relation exists, and then insert/update.

    A.- Enclose the an INSERT query in a try block, and, in case of error, make an update query. That would save all the checks when the relation doesn’t exists…

    B.- Make all INSERT ON DUPLICATE UPDATE. This is gonna do exactly the same as in “A”, but you don’t need to worry about exceptions.

    Definitely your second idea is absolutely wrong.

    I would not create a table keywords, since you only need the keyword itself… then I would define my model_has_keyword like this:

    CREATE TABLE model_has_keyword (
      model_id         INT NOT NULL,
      keyword          VARCHAR(50) NOT NULL,
      timesCount       INT NOT NULL,
      roundCount       INT NOT NULL,
      PRIMARY KEY (model_id,keyword)
    );
    

    and update it like this:

    INSERT INTO model_has_keyword 
      (model_id,keyword,timesCount,$myIntValue) 
    VALUES 
      ($model_id,$keyword,0,0) 
    ON DUPLICATE KEY UPDATE 
      timesCount=timesCount+1,roundCount=roundCount + $myIntValue
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to start developing a "simple" game with HTML5 and I'm quite confused
Am developing a game using HTML5 and CSS3. I have a bunch of divs
I have been developing a game in the HTML5/Javascript new canvas feature, and all
I am developing an HTML5 canvas based mini-game and I can't seem to organize
I'm developing a website that has a HTML5 video. It looks like when ogg
I have a page I am developing in .net using HTML5 intended for a
I am developing HTML5 css3 & js based game. So i want everything should
I'm developing an HTML5 application. I want to parse an XML like this one:
I'm developing a PHP/HTML5/CSS3 page and have run into an issue. I somehow had
I am developing an HTML5 player on Windows, but I have some real difficulties

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.