V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  napoleonu  ›  全部回复第 11 页 / 共 68 页
回复总数  1345
1 ... 7  8  9  10  11  12  13  14  15  16 ... 68  
2012-03-05 15:49:04 +08:00
回复了 underone 创建的主题 问与答 你见过的小清新网站都有些啥?
http://www.geekpark.net/portal/seed 打开的那一刻我就心里想着“有朝一日我一定会抄袭走的”
2012-03-05 11:53:00 +08:00
回复了 toothpaste 创建的主题 MySQL MySQL 表的设计
@lepture 你看下顶楼是怎么写的。
2012-03-05 11:13:19 +08:00
回复了 toothpaste 创建的主题 MySQL MySQL 表的设计
2012-03-05 10:42:19 +08:00
回复了 toothpaste 创建的主题 MySQL MySQL 表的设计
@Tianpu @lepture @lenmore @toothpaste

测试看来,如果in(list)中list是一个子查询,不管父查询有没有用上索引,效果都很差。
2012-03-05 10:34:29 +08:00
回复了 toothpaste 创建的主题 MySQL MySQL 表的设计
说明:
1.in(list)运算,如果list是一个明确的项目列表,in(list)运算性能尚可。
2.in(list)运算,如果list是一个子查询,那么只有在满足 1)父查询是覆盖索引查询 2)过滤性够好(我的不知道错误还是正确的85%无效结果的排除率) 的时候父查询才会用的上索引,反之则用不上索引。

就如上面那句
select feed_name, feed_url from feed where feed_id = ( select feed_id from user,subscription where user.user_id = subscription.user_id and user_name = 'Tom');
大部分人的想法可能是 首先 子查询查询一堆feed_id 之后 返回feed_id的列表给父查询
而实际上MySQL优化器并不会这么做,而是先对feed表进行全表扫描,或者如果有个 idx1(feed_id,feed_name, feed_url) 索引,则进行全索引扫描,之后把feed表的feed_id代入到子查询,效率有多低相信你应该知道。至少目前已经GA的版本都是这样,not in一样的方式。

mysql> show create table a\G
*************************** 1. row ***************************
Table: a
Create Table: CREATE TABLE `a` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`uid` int(10) NOT NULL,
`time` datetime NOT NULL,
`type` tinyint(4) DEFAULT NULL,
`status` varchar(320) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_uid` (`uid`)
) ENGINE=InnoDB AUTO_INCREMENT=500001 DEFAULT CHARSET=utf8
1 row in set (0.00 sec)

+----+-----+---------------------+------+-----------+
| id | uid | time | type | status |
+----+-----+---------------------+------+-----------+
| 1 | 1 | 2012-01-16 17:34:24 | 1 | vvvvvvvvv |
| 2 | 1 | 2012-01-16 17:34:10 | 2 | vvvvvvvvv |
| 3 | 1 | 2012-01-11 12:16:56 | 0 | vvvvvvvvv |
| 4 | 1 | 2012-01-16 17:34:24 | 1 | vvvvvvvvv |
| 5 | 1 | 2012-01-16 17:34:10 | 2 | vvvvvvvvv |
+----+-----+---------------------+------+-----------+

mysql> select * from c;
+----+
| id |
+----+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |
| 9 |
| 10 |
+----+
10 rows in set (0.00 sec)

1.如果list是一个明确的项目列表
mysql> explain select count(*) from a where uid in (1,2,3,4,5,6,7,8,9,10)\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: a
type: range
possible_keys: idx_uid
key: idx_uid
key_len: 4
ref: NULL
rows: 4996
Extra: Using where; Using index
1 row in set (0.00 sec)

mysql> select sql_no_cache count(id) from b where uid in (1,2,3,4,5,6,7,8,9,10);
+-----------+
| count(id) |
+-----------+
| 5000 |
+-----------+
1 row in set (0.00 sec)

2.如果list是一个子查询,满足 1)父查询是覆盖索引查询 2)过滤性够好 父查询用的上索引
mysql> explain select count(uid) from a where uid in (select id from c)\G
*************************** 1. row ***************************
id: 1
select_type: PRIMARY
table: a
type: index
possible_keys: NULL
key: idx_uid
key_len: 4
ref: NULL
rows: 500101
Extra: Using where; Using index
*************************** 2. row ***************************
id: 2
select_type: DEPENDENT SUBQUERY
table: c
type: unique_subquery
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: func
rows: 1
Extra: Using index
2 rows in set (0.00 sec)

mysql> select sql_no_cache count(uid) from a where uid in (select id from c);
+------------+
| count(uid) |
+------------+
| 5000 |
+------------+
1 row in set (1.61 sec)

2.如果list是一个子查询,不满足 1)父查询是覆盖索引查询 2)过滤性够好 父查询用不上索引
mysql> explain select count(time) from a where uid in (select id from c)\G
*************************** 1. row ***************************
id: 1
select_type: PRIMARY
table: a
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 500101
Extra: Using where
*************************** 2. row ***************************
id: 2
select_type: DEPENDENT SUBQUERY
table: c
type: unique_subquery
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: func
rows: 1
Extra: Using index
2 rows in set (0.00 sec)

mysql> select sql_no_cache count(time) from a where uid in (select id from c);
+-------------+
| count(time) |
+-------------+
| 5000 |
+-------------+
1 row in set (1.68 sec)
2012-03-04 23:54:46 +08:00
回复了 toothpaste 创建的主题 MySQL MySQL 表的设计
又不是计算机三级考试,不用在意范式的。现在计算机的计算能力和存储能力,范式已经不适合了。

in运算绝对禁止。
2012-03-04 22:32:33 +08:00
回复了 toothpaste 创建的主题 MySQL MySQL 表的设计
当你深入了解MySQL的各种功能的实现方式,特征的时候应该就会更容易设计出比较优雅且性能好的表结构来。

就你上面的问题,我的一个小建议是做适当的数据冗余

例如
table subscription
*subscription_id, user_id,user_name, feed_id, ...
那么你上面的查询就是
select f.feed_name,f.feed_url from feed f,subscription s where s.user_name='Tom' and f.feed_id = s.feed_id;

再例如
table subscription
*subscription_id, user_id,user_name,feed_id, feed_name,feed_url, feed_description
那么你上面的查询就是
select feed_name,feed_url from subscription where user_name='Tom';
2012-03-03 02:43:56 +08:00
回复了 napoleonu 创建的主题 git 复制 Project Babel 的 Jekyll Theme
今天把首页改成了传统博客的样式,可以自定义显示多少篇博文,并增加了分页。
2012-03-03 02:41:09 +08:00
回复了 Sunya 创建的主题 天黑以后 20120303 午夜俱乐部
不知道自己在干什么,要干什么。。
2012-03-01 01:19:11 +08:00
回复了 fanzeyi 创建的主题 天黑以后 20120301 午夜俱乐部
我知道这个很难,但是还是求帮忙转发下

http://weibo.com/napoleonu#1330535822569 第一条微博。。

多谢!!!
2012-02-29 00:59:28 +08:00
回复了 kojp 创建的主题 天黑以后 20120229 午夜俱乐部
生日快乐!
2012-02-28 21:36:44 +08:00
回复了 hq5261984 创建的主题 宽带症候群 v2ex里有多少是下载控??
HDC:下载152G 上传1.9T
CHD:下载34G 上传360G
TTG:下载47G 上传1.1T
2012-02-28 21:08:33 +08:00
回复了 napoleonu 创建的主题 git 复制 Project Babel 的 Jekyll Theme
@bcxx Jekyll做社区,做不到的吧。。
2012-02-28 14:18:51 +08:00
回复了 napoleonu 创建的主题 git 复制 Project Babel 的 Jekyll Theme
@dongsheng 是的哦,这个是自动被过滤掉了吧,冒号
2012-02-28 14:11:04 +08:00
回复了 napoleonu 创建的主题 git 复制 Project Babel 的 Jekyll Theme
弄了一上午,基本可用了。
2012-02-28 01:30:31 +08:00
回复了 fanzeyi 创建的主题 天黑以后 20120228 午夜俱乐部
恩,谢谢各位,貌似好些了,折腾完毕了。睡觉了,晚安。。
2012-02-28 01:00:57 +08:00
回复了 fanzeyi 创建的主题 天黑以后 20120228 午夜俱乐部
各位 https://github.com 可以正常访问么?突然就断断续续一会,之后就只能防火墙外面访问了,push也不通。
2012-02-28 00:52:00 +08:00
回复了 fanzeyi 创建的主题 天黑以后 20120228 午夜俱乐部
https://github.com 访问断断续续,郁闷。
1 ... 7  8  9  10  11  12  13  14  15  16 ... 68  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   961 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 29ms · UTC 20:01 · PVG 04:01 · LAX 13:01 · JFK 16:01
Developed with CodeLauncher
♥ Do have faith in what you're doing.