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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:15:04+00:00 2026-05-21T03:15:04+00:00

Please consider the table bd.nn that contains roughly 19 million records: > SELECT n,

  • 0

Please consider the table bd.nn that contains roughly 19 million records:

> SELECT n, name, cdf from bd.nn limit 4;
+-------+-------------------------------+--------+
| n     | name                          | cdf    |
+-------+-------------------------------+--------+
| 10002 | JOJE                          | NULL   |
| 10010 | AUGUSTINA                     | NULL   |
| 10029 | CARDOS                        | NULL   |
| 10037 | DE FRITOS                     | NULL   |
+-------+-------------------------------+--------+

Primary key in n with BTREE type.

The task is to UPDATE field cdf from the following table;

> SELECT * from n_cdf_temp;
+-------+--------+
| n     | cdf    |
+-------+--------+
| 10002 | 16     |
+-------+--------+

Primary key in n with BTREE type.
Both n fields still have char(9) type although it’s planned to move to int type.

This table only has one record as an example but should have some million lines as well.

The commands I tried were, by this order:

UPDATE bd.nn y SET cdf = (SELECT cdf from temp.n_cdf_temp t WHERE t.n = y.n);

UPDATE bd.nn y SET cdf = (SELECT cdf from temp.n_cdf_temp t WHERE t.n = y.n) WHERE y.n in (SELECT n from temp.n_cdf_temp WHERE cdf IS NOT NULL);

UPDATE bd.nn y INNER JOIN temp.n_cdf_temp t ON y.n=t.n SET y.cdf = t.cdf;

UPDATE bd.nn y FORCE KEY (PRIMARY) INNER JOIN temp.n_cdf_temp t ON y.n=t.n SET y.cdf = t.cdf;

The problem is that this update takes a long time.
In my development laptop (Core 2 Duo) with MyISAM tables, the update for the fourth command took 6,5 seconds and for the third about 30 seconds.
If n_cdf_temp has 1000 records, the MyISAM engine takes 45 seconds.

But in the production server, with InnoDB tables, the update took 14 minutes when n_cdf_temp had only one record.
When n_cdf_temp had 1000 records, the query took ca. 18 minutes.
MySQL version 5.0.67 in old Linux box P4, 1GB RAM.

What else should I do to greatly improve the UPDATE performance for acceptable time?

ETA EXPLAIN for SELECT version of queries 3:

EXPLAIN SELECT y.n, t.cdf from bd.nn y INNER JOIN temp.n_cdf_temp t ON y.n=t.n\G 
** 1. row id: 1 select_type: SIMPLE table: t type: index possible_keys: PRIMARY key: cdf key_len: 2 ref: NULL rows: 1 Extra: Using index 
** 2. row id: 1 select_type: SIMPLE table: y type: ALL possible_keys: PRIMARY key: NULL key_len: NULL ref: NULL rows: 18744700 Extra: Range checked for each record (index map: 0x1) –
  • 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-21T03:15:05+00:00Added an answer on May 21, 2026 at 3:15 am

    From the EXPLAIN you posted, it appears that it is refusing to use the index on your ‘y’ table. In row 2 of the EXPLAIN, note ‘key: NULL key_len: NULL’. Is it possible that the datatypes for the primary keys of the 2 tables are different?

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

Sidebar

Related Questions

Please consider this sql statements Create table abc (A int, B int ) insert
Please consider the following scripts. Create Table: IF OBJECT_ID('Colortable') IS NOT NULL DROP TABLE
Consider the following table: People FirstName nvarchar(50) LastName nvarchar(50) Let's assume for the moment
Here is the code that will help you understand my question: create table con
I need to copy some data from one table to another in Oracle, while
I've got about 20,000 rows in an INNODB table called 'cards', so FULLTEXT is
Let's say I need to have the ratio of "number of items available from
I'm trying to create a efficient query which will retrieve 'projects' from a database
I'm trying to render a calendar with Rails and Haml . The dates used
With reference to this post: How to implement tag counting I have implemented the

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.