php - Need to insert in products table from more than one tables with dynamic user id
问题描述
I have 3 tables users, products and temp_table. i have imported an xlsx file having 1,00,000 records in to temp_table. now i have to insert these records to products table. and here i have to save user_id from users table to products table as well. Note: user_id is dynamic(i.e. in xlsx file there is a column called email and I have created a new user for their email). so in products table user_id will be dynamically inserted. I have used below query, but it is taking too much time. and sometimes my MySQL get locked.
INSERT INTO products
(user_id,
brand_id,
points_discount,
amount,
sub_total,
added_on)
SELECT users.user_id,
brand_id,
discount,
amount,
sub_total,
added_on
FROM temp_table
INNER JOIN users
ON email = users.email;
Please help me to solve this problem.
解决方案
在和表的email
列上创建索引。还要确保两列具有相同的temp_table
users
datatype
ALTER TABLE temp_table ADD KEY `idx_email` (`email`);
ALTER TABLE users ADD KEY `idx_email` (`email`);
推荐阅读
- python - ModuleNotFoundError:没有名为“bs4”的模块,但在 Python 3.8.5 上使用 PIP3 正确安装
- javascript - 当我将变量作为文档参考传递时无法获取文档快照
- google-sheets - 谷歌表计时公式
- c++ - C++在有序链表中搜索节点
- javascript - 在 REACTJS 中渲染时出现周期性错误
- azure - Azure 应用程序网关 WAF_V2 ARM 部署失败
- jquery - 通过 https 调用在 localhost 上运行的 Owin 服务
- html - 如何将内联 CSS 添加到 Wordpress Visual Composer 中?
- javascript - 如何获得两个不同日期之间的分钟数?
- git - 我错误地删除了一个git分支,我该如何恢复它?