avatar
问个Index的问题# Database - 数据库
p*3
1
书法--天苍苍,夜茫茫, 风吹草低现牛羊
avatar
s*g
2
比如说设计一个银行的数据库,
有一个table叫transaction(transactionID, accountID, date, ...)
-------------
这个表显然经常需要更新,主要是一条一条的insert操作
这样看来,为了performance,尽量减少index,那么不应该在accountID上建index
不然,每次insert都需要更新这个index(?)
然而,用户(和银行)也需要查询某账户近期的所有transactions
这样似乎又需要给accountID建一个index
想请教一下实际设计中是怎么做的?谢谢!
avatar
K*y
3
不懂,觉得挺好看的
avatar
t*n
4
Which database are you using? If it is SQL Server, it looks like accountID+
date is a good candidate for the clustered index. In SQL Server, a clustered
index is actually the table itself, so have no fear of inserting.

【在 s******g 的大作中提到】
: 比如说设计一个银行的数据库,
: 有一个table叫transaction(transactionID, accountID, date, ...)
: -------------
: 这个表显然经常需要更新,主要是一条一条的insert操作
: 这样看来,为了performance,尽量减少index,那么不应该在accountID上建index
: 不然,每次insert都需要更新这个index(?)
: 然而,用户(和银行)也需要查询某账户近期的所有transactions
: 这样似乎又需要给accountID建一个index
: 想请教一下实际设计中是怎么做的?谢谢!

avatar
i*a
5
从个人审美看,这幅逸趣横生,契合风吹草低这句里的怡然自得。。。

【在 p*****3 的大作中提到】
: 书法--天苍苍,夜茫茫, 风吹草低现牛羊
avatar
z*3
6
这个个人感觉还是一个比较复杂的问题,如果一般的index的话是指b+ tree,并不是每
次insert都会产生balance tree的操作。只有某个node全充满的时候才会,进行
balance tree操作,或许还有left rotation和right rotation的操作。
如果使用mysql的话,可以设定经常插入的数据库的engine是inndo,不要每次insert都
commit,先insert若干条,再commit,然后用master-slave replication把数据同步到
,经常查询的一个数据库,而这个数据库的engine是myisam。
oracle的话,个人感觉可以对date,建立一个bitmap index,这样的话,其实不会有
tree的运算,每次只是没有操作或是更新一下某个gap的up或low bound。然后建一个
job,每隔一段时间dbms_stats.gather_stats,这样的话,可以尽快更新execution
plan,达到更好的效果。
avatar
p*3
7
谢谢版大

【在 i***a 的大作中提到】
: 从个人审美看,这幅逸趣横生,契合风吹草低这句里的怡然自得。。。
avatar
w*e
8
不太同意
要是clustered index的话, 经常insert会产生fragmentation的(internal and
external), 对吧?
所以才有rebuild or reorganize index.....
(不是"no fear of insertting")

clustered

【在 t****n 的大作中提到】
: Which database are you using? If it is SQL Server, it looks like accountID+
: date is a good candidate for the clustered index. In SQL Server, a clustered
: index is actually the table itself, so have no fear of inserting.

avatar
p*3
9
谢谢KittyGray

【在 K*******y 的大作中提到】
: 不懂,觉得挺好看的
avatar
z*3
10
同意,wildhorse的意见,cluster index说穿了还是tree,只要有插入,还是会有
balance tree的操
作,而且如果后update或是insert的话一样是低效的。

【在 w*******e 的大作中提到】
: 不太同意
: 要是clustered index的话, 经常insert会产生fragmentation的(internal and
: external), 对吧?
: 所以才有rebuild or reorganize index.....
: (不是"no fear of insertting")
:
: clustered

avatar
a*p
11
真好!狂赞!
avatar
s*e
12
bitmap index on date field, if date is really timestamp, that is abusing
bitmap index.
avatar
q*x
13
RE,同不懂,同赞,呵呵~

【在 K*******y 的大作中提到】
: 不懂,觉得挺好看的
avatar
B*g
14
minimum index != no index
b-tree index is ok

【在 s******g 的大作中提到】
: 比如说设计一个银行的数据库,
: 有一个table叫transaction(transactionID, accountID, date, ...)
: -------------
: 这个表显然经常需要更新,主要是一条一条的insert操作
: 这样看来,为了performance,尽量减少index,那么不应该在accountID上建index
: 不然,每次insert都需要更新这个index(?)
: 然而,用户(和银行)也需要查询某账户近期的所有transactions
: 这样似乎又需要给accountID建一个index
: 想请教一下实际设计中是怎么做的?谢谢!

avatar
j*n
15
that's why there is another thing called fill factor. which can reduce
fragmentation / page split problem.
for me, i'd use combination of transactionID, accountID, and date for the
clustered index. why? most likely transactionID is incremental. it
guarantees new row is appended into the last data page. what about "hot spot
"? it is not a problem for SQL Server 7.0 and later versions if less 1,000
inserts per second.

【在 w*******e 的大作中提到】
: 不太同意
: 要是clustered index的话, 经常insert会产生fragmentation的(internal and
: external), 对吧?
: 所以才有rebuild or reorganize index.....
: (不是"no fear of insertting")
:
: clustered

avatar
w*e
16
恩, fill factor能"减少"fragmentation, 但是
这是银行的transaction, 你认为多少fill factor合适?

spot

【在 j*****n 的大作中提到】
: that's why there is another thing called fill factor. which can reduce
: fragmentation / page split problem.
: for me, i'd use combination of transactionID, accountID, and date for the
: clustered index. why? most likely transactionID is incremental. it
: guarantees new row is appended into the last data page. what about "hot spot
: "? it is not a problem for SQL Server 7.0 and later versions if less 1,000
: inserts per second.

avatar
B*g
17
不明白。how "guarantees new row is appended into the last data page" will
imporve the search based on accountID?

spot

【在 j*****n 的大作中提到】
: that's why there is another thing called fill factor. which can reduce
: fragmentation / page split problem.
: for me, i'd use combination of transactionID, accountID, and date for the
: clustered index. why? most likely transactionID is incremental. it
: guarantees new row is appended into the last data page. what about "hot spot
: "? it is not a problem for SQL Server 7.0 and later versions if less 1,000
: inserts per second.

avatar
j*n
18
usually start from 80%
i use to worked for a financial firm with maximum transaction more than 1
million per day. 80% fill factor handles well.

【在 w*******e 的大作中提到】
: 恩, fill factor能"减少"fragmentation, 但是
: 这是银行的transaction, 你认为多少fill factor合适?
:
: spot

avatar
j*n
19
less fragmentation will improve performance, right?
accountid is in the clustered index, index seek will perform.

【在 B*****g 的大作中提到】
: 不明白。how "guarantees new row is appended into the last data page" will
: imporve the search based on accountID?
:
: spot

avatar
B*g
20
I thought when create clustered index on TransID, AcctID, Date, the data
will stored based on TransID (I believe it is unique) order, so nothing
ordered based on AcctID.

【在 j*****n 的大作中提到】
: less fragmentation will improve performance, right?
: accountid is in the clustered index, index seek will perform.

avatar
j*n
21
hmm... you right. however, sql serve can still use B tree instead of hash
tree.
if you doubt with that, we can go for non-clustered index with accountid +
date with fill factor = 80%; then reindex nightly. should work.

【在 B*****g 的大作中提到】
: I thought when create clustered index on TransID, AcctID, Date, the data
: will stored based on TransID (I believe it is unique) order, so nothing
: ordered based on AcctID.

avatar
gy
22
我纯属抬杠哈...
即使80% fillfactor, 也仍然会有fragmentation在银行这种high volume transaction
里,
只是时间的早晚而已
所以reindex是不可少的.

【在 j*****n 的大作中提到】
: usually start from 80%
: i use to worked for a financial firm with maximum transaction more than 1
: million per day. 80% fill factor handles well.

avatar
gy
23
恩, 所以建composite index时是很有考虑的

【在 B*****g 的大作中提到】
: I thought when create clustered index on TransID, AcctID, Date, the data
: will stored based on TransID (I believe it is unique) order, so nothing
: ordered based on AcctID.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。