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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:33:35+00:00 2026-05-27T13:33:35+00:00

I have this structure of my db: CREATE TABLE IF NOT EXISTS `peoples` (

  • 0

I have this structure of my db:

CREATE TABLE IF NOT EXISTS `peoples` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;

For customers.

CREATE TABLE IF NOT EXISTS `peoplesaddresses` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `people_id` int(10) unsigned NOT NULL,
  `phone` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
  `address` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;

For their addresses.

CREATE TABLE IF NOT EXISTS `peoplesphones` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `people_id` int(10) unsigned NOT NULL,
  `phone` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
  `address` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;

For their phones.

UPD4

ALTER TABLE peoplesaddresses DISABLE KEYS; 
ALTER TABLE peoplesphones DISABLE KEYS; 

ALTER TABLE peoplesaddresses ADD INDEX i_phone (phone);
ALTER TABLE peoplesphones ADD INDEX i_phone (phone);
ALTER TABLE peoplesaddresses ADD INDEX i_address (address);
ALTER TABLE peoplesphones ADD INDEX i_address (address);

ALTER TABLE peoplesaddresses ENABLE KEYS;
ALTER TABLE peoplesphones ENABLE KEYS;

END UPD4

CREATE TABLE IF NOT EXISTS `order` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `people_id` int(10) unsigned NOT NULL,
  `name` varchar(255) CHARACTER SET utf8 NOT NULL,
  `phone` varchar(255) CHARACTER SET utf8 NOT NULL,
  `adress` varchar(255) CHARACTER SET utf8 NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ;

INSERT INTO `order` (`id`, `people_id`, `name`, `phone`, `adress`) VALUES
(1, 0, 'name1', 'phone1', 'address1'),
(2, 0, 'name1_1', 'phone1', 'address1_1'),
(3, 0, 'name1_1', 'phone1', 'address1_2'),
(4, 0, 'name2', 'phone2', 'address2'),
(5, 0, 'name2_1', 'phone2', 'address2_1'),
(6, 0, 'name3', 'phone3', 'address3'),
(7, 0, 'name4', 'phone4', 'address4'),
(8, 0, 'name1_1', 'phone5', 'address1_1'),
(9, 0, 'name1_1', 'phone5', 'address1_2'),
(11, 0, 'name1', 'phone1', 'address1'),
(10, 0, 'name1', 'phone1', 'address1');

Production base have over 9000 records. Is there way to execute this 3 update query’s little more faster, than now (~50 min on dev machine).

INSERT INTO peoplesphones( phone, address ) 
SELECT DISTINCT `order`.phone, `order`.adress
FROM `order` 
GROUP BY `order`.phone;

Fill peoplesphones table with unique phones

INSERT INTO peoplesaddresses( phone, address ) 
SELECT DISTINCT `order`.phone, `order`.adress
FROM `order` 
GROUP BY `order`.adress;

Fill peoplesaddresses table with unique adress.
The next three querys are very slow:

UPDATE peoplesaddresses, peoplesphones SET peoplesaddresses.people_id = peoplesphones.id WHERE peoplesaddresses.phone = peoplesphones.phone;

UPDATE peoplesaddresses, peoplesphones SET peoplesphones.people_id = peoplesaddresses.people_id WHERE peoplesaddresses.address = peoplesphones.address;

UPDATE `order`, `peoplesphones` SET `order`.people_id = `peoplesphones`.people_id where `order`.phone = `peoplesphones`.phone;

Finally fill people table, and clear uneccessary fields.

INSERT INTO peoples( id, name ) 
SELECT DISTINCT `order`.people_id, `order`.name
FROM `order` 
GROUP BY `order`.people_id;

ALTER TABLE `peoplesphones`
  DROP `address`;

ALTER TABLE `peoplesaddresses`
  DROP `phone`;

So, again: How can I make those UPDATE query’s a little more faster? THX.

UPD: I forgott to say: I need to do it at once, just for migrate phones and adresses into other tables since one people can have more than one phone, and can order pizza not only at home.

UPD2:

MySQL Variables
UPD3:

Replace slow update querys on this (without with) get nothing.

UPDATE  peoplesaddresses
LEFT JOIN
        peoplesphones
ON      peoplesaddresses.phone = peoplesphones.phone
SET     peoplesaddresses.people_id = peoplesphones.id;

UPDATE  peoplesphones
LEFT JOIN
        `peoplesaddresses`
ON      `peoplesaddresses`.address = `peoplesphones`.address
SET     `peoplesphones`.people_id = `peoplesaddresses`.people_id;

UPDATE  `order`
LEFT JOIN
        `peoplesphones`
ON      `order`.phone = `peoplesphones`.phone
SET     `order`.people_id = `peoplesphones`.people_id;

UPD4 After adding code at the top (upd4), script takes a few seconds for execute. But on ~6.5k query it terminate with text: “The system cannot find the Drive specified”.

Thanks to All. Especially to xQbert and Brent Baisley.

  • 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-27T13:33:36+00:00Added an answer on May 27, 2026 at 1:33 pm

    50 minutes for 9000 records is a bit ridiculous, event without indexes. You might as well put the 9000 records in Excel and do what you need to do. I think there is something else going on with your dev machine. Perhaps you have mysql configured to use very little memory? Maybe you can post the results of this “query”:

    show variables like "%size%";
    

    Just this morning I did an insert(ignore)/select on 2 tables (one into another), both with over 400,000 records. 126,000 records were inserted into the second table, it took a total of 2 minutes 13 seconds.

    I would say put indexes on any of the fields you are joining or grouping on, but this seems like a one time job. I don’t think the lack of indexes is your problem.

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

Sidebar

Related Questions

Table Structure CREATE TABLE IF NOT EXISTS `blogs` ( `id` int(11) NOT NULL auto_increment,
I have this database structure, SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO; CREATE TABLE IF NOT EXISTS `announces` (
I have the following table structure: CREATE TABLE a ( a_id int(10) unsigned NOT
I have the following structure SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO; CREATE TABLE IF NOT EXISTS `sis_param_tax` (
Hi this is my table structure CREATE TABLE IF NOT EXISTS `sms_report` ( `R_id`
This is the master table structure: CREATE TABLE IF NOT EXISTS `gf_film` ( `film_id`
I have this table structure on a SQL Server 2008 R2 database: CREATE TABLE
Suppose we have 2 tables, a and b: CREATE TABLE a (id_a INT NOT
The structure of my mysql table is: CREATE TABLE IF NOT EXISTS `tb_hour_counts` (
I have in my MySQL database these two tables: CREATE TABLE IF NOT EXISTS

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.