社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

Daniel Farrell

Daniel Farrell 最近创建的主题
Daniel Farrell 最近回复了
5 年前
回复了 Daniel Farrell 创建的主题 » MySQL从另一个表更新值

更新联接的经典用例。

UPDATE songs
JOIN artists ON song.artist = artist.name
SET songs.artist_id = artists.artist_id;

然而,这些语法都不会改变数据已经是最新的这一事实。

查询正常,0行受影响(0.00秒) 匹配的行:27已更改:0警告:0

二十七 songs 行匹配这个 artist_id 每个都已设置为对应的 artists.artist_id . 所以O行被影响或改变。未生成警告。仅仅因为查询匹配行并不意味着它改变了它们。

6 年前
回复了 Daniel Farrell 创建的主题 » 查询1800万行以上mysql数据库的替代解决方案

我在Docker中启动了一个MySQL服务器,就像这样,只是使用默认值:

docker run -d --rm --name mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=true mysql

并创建了这样的数据库:

docker exec -it mysql mysql -e 'create database if not exists test'

然后像这样连接交互式会话:

docker exec -it mysql mysql test

然后我在上面填了3200万个随机日期…

INSERT into dates select date(from_unixtime(rand()*unix_timestamp(now())) );

然后运行几十次:

INSERT into dates select date(from_unixtime(rand()*unix_timestamp(now())) ) from dates;

现在我的约会次数几乎是你的两倍:

mysql> explain select * from dates;
+----+-------------+-------+------------+------+---------------+------+---------+------+----------+----------+-------+
| id | select_type | table | partitions | type | possible_keys | key  | key_len | ref  | rows     | filtered | Extra |
+----+-------------+-------+------------+------+---------------+------+---------+------+----------+----------+-------+
|  1 | SIMPLE      | dates | NULL       | ALL  | NULL          | NULL | NULL    | NULL | 33497947 |   100.00 | NULL  |
+----+-------------+-------+------------+------+---------------+------+---------+------+----------+----------+-------+
1 row in set, 1 warning (0.00 sec)

最后,我可以演示如何快速搜索表格:

mysql>  select count(*), d from dates where d between '2001-01-01' and '2001-12-31' group by d order by d desc;  
....
365 rows in set (4 min 31.17 sec)

有道理,2001年每天都有几千个结果。(请记住,这些日期是在1970年到现在之间随机分布的)。

没有索引或任何东西,也没有sql优化。花了4.5分钟。希望这能为您的服务器和查询性能提供一个基线。