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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:26:52+00:00 2026-05-25T11:26:52+00:00

I have 2 tables in MySql Table_A { pk_A VARCHAR 150 PRIMARY KEY, random_data

  • 0

I have 2 tables in MySql

Table_A { pk_A VARCHAR 150 PRIMARY KEY, random_data } ~ 9500 rows
Table_B { pk_B VARCHAR 150, more_random_data } ~ 50000 rows

Relationship between them is one-to-many, pk_A will be found multiple times in Table_B on col pk_B.

My problem is:

  • if i enable indexing on pk_B , php/mysql CRUD works fine, but a JOIN or anyother query from command line involving both tables takes a long time

  • if i disable indexing on pk_B, php/mysql CRUD becomes laggish, but a JOIN or anyother query from command line involving both tables is instantaneous

How can i improve my database performance (i could modify my pk’s from varchar to int(11)) but i wondered if there are other workarounds available

Thanks

  • 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-25T11:26:54+00:00Added an answer on May 25, 2026 at 11:26 am

    A few things to speed up your queries. As the many comments suggest; you always want to keep your primary keys as small as is reasonable. A short string, say VARCHAR(10) won’t cause you much pain, but much larger than that, you may want to use a surrogate key. This can be made more or less transparent by making the natural key be unique, but not in the primary key.

    Table_A { pk_A VARCHAR 150 PRIMARY KEY, random_data } ~ 9500 rows
    Table_B { pk_B VARCHAR 150, more_random_data } ~ 50000 rows

    Your schema should probably look a bit like this:

    CREATE TABLE `Table_A` (
        `id` INTEGER AUTO_INCREMENT PRIMARY KEY,
        `A_name` VARCHAR(150) UNIQUE NOT NULL,
        -- other columns
    ) ENGINE = InnoDB;
    
    CREATE TABLE `Table_B` (
        `id` INTEGER AUTO_INCREMENT PRIMARY KEY,
        `B_name` VARCHAR(150) UNIQUE NOT NULL,
        `A_id` INTEGER REFERENCES `Table_A`(`id`),
        -- other columns
    ) ENGINE = InnoDB;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using php and mysql I have two tables, a users table and a profiles
I have a mysql db with 10 tables. Each table drives a website where
I have a MySQL table with approximately 3000 rows per user. One of the
Consider a database(MSSQL 2005) that consists of 100+ tables which have primary keys defined
I have a MySql db with innoDB tables. Very simplified this is how two
I have this classifieds website, and I have about 7 tables in MySql where
I have a MySQL table defined: File -------------------------- ID int(11) PK name varchar(100) customerId
I have an e-commerce MySQL database with the following tables: **Product** ---------- productID -
i'm new in php and mysql i have a problem i have 2 tables
I have two MySQL tables: User (with an auto-incremented pk id) and WaitingUser which

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.