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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:54:04+00:00 2026-05-26T02:54:04+00:00

I have two tables that get joined regularly. Table One is about 1 Million

  • 0

I have two tables that get joined regularly.

Table One is about 1 Million rows and grows daily. Table Two is always about 200k less than Table One. Furthermore, Table Two is truncated and repopulated every night from a report downloaded from an outside service. The UPDATE..JOIN query I use isn’t too speedy, so I’m looking for a possible remedy.

Table One’s structure:

#I grow daily and currently am around 1 million rows.
CREATE TABLE table_one(
 id INT NOT NULL AUTO_INCREMENT,
 sku VARCHAR(30), 
 other_one VARCHAR(30),
 PRIMARY KEY(id)
);

Table Two’s structure:

#I get truncated every night and am about 200k less rows than Table One.
CREATE TABLE table_two(
 id INT NOT NULL AUTO_INCREMENT,
 sku VARCHAR(30), 
 other_two INT,
 PRIMARY KEY(id)
);

Note that the other_one and other_two fields on both tables are just there to demonstrate that each table has fields (mostly varchar) beyond id and sku but there are actually many different columns on each table. I’m not sure it matters but SKU is unique on table two and but only unique about 95% of the time on table one. Because of this, uniqueness is not enforced on either table in MySQL.

So here is my workflow and question:

1) A bunch of new rows get added to Table One during the day.
2) Each night Table Two is truncated (all rows deleted)
3) A report is downloaded from a third party as a CSV flatfile. That report is then loaded into Table Two using a LOAD DATA LOCAL INFILE command.
4) 3 queries are run that update Table One data and involve a JOIN. They all look very similar to this:

UPDATE table_one t1
JOIN table_two t2 ON t2.sku = t1.sku
SET t1.other_one = "Other two was greater than zero!"
WHERE t1.other_one IS NULL AND t2.other_two > 0

With the number of rows I have, doing JOINs between these two tables seems to take up quite a bit of time. I was curious as to, with 3 heavy update queries, would it be best to create some index for these tables. The issue being that these indexes would most likely have to be recreated each night when Table Two gets populated. I don’t know how this might affect population speed nor do I know which type of index I should use.

  • 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-26T02:54:05+00:00Added an answer on May 26, 2026 at 2:54 am

    You certainly want to have indices for the tables. On table two, drop the index before truncating the table and reloading the data. Once the data has been reloaded, re-create your index.

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

Sidebar

Related Questions

I have two tables that are joined together. A has many B Normally you
I have two tables that should be joined together by a foreign key relationship,
I have two tables that are related via a mapping table: keywords titles I
Suppose I have two tables that are linked (one has a foreign key to
I have two tables: P and PC (master/detail joined by the column Id) Table
I currently have two joined tables in a SQL Server database, one with news
I have two tables that are considered a single entity in my domain model.
I have two tables that I am joining with the following query... select *
Let's say I have two tables that look like this: TH TH TH TH
If i have two tables that have nothing in common I want to do

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.