由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - 问个Index的问题
相关主题
如何决定indexSQL 2008 Create Index vs Rebuild Index (Alter Index)
more q: how to make database size smallerlog shipping 问题
When should I reorganize Index/Rebuuild Index?SQL 2000 create index 問題
被人鄙视了最近找工作的经验 SQL DBA更新
Oracle Group and Index questioncommon misconception in Oracle
求助:找出现2次及以上的记录骑驴找马记
indexing就是设置primary key吗?BJ,那个COLUMNSTORE INDEX是不是BITMAP INDEX啊
请教 sql server index问题为啥RDBMS只用一个Index? (转载)
相关话题的讨论汇总
话题: index话题: accountid话题: clustered话题: date话题: sql
进入Database版参与讨论
1 (共1页)
s******g
发帖数: 287
1
比如说设计一个银行的数据库,
有一个table叫transaction(transactionID, accountID, date, ...)
-------------
这个表显然经常需要更新,主要是一条一条的insert操作
这样看来,为了performance,尽量减少index,那么不应该在accountID上建index
不然,每次insert都需要更新这个index(?)
然而,用户(和银行)也需要查询某账户近期的所有transactions
这样似乎又需要给accountID建一个index
想请教一下实际设计中是怎么做的?谢谢!
t****n
发帖数: 263
2
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
: 想请教一下实际设计中是怎么做的?谢谢!

z*3
发帖数: 33
3
这个个人感觉还是一个比较复杂的问题,如果一般的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,达到更好的效果。
w*******e
发帖数: 1622
4
不太同意
要是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.

z*3
发帖数: 33
5
同意,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

s******e
发帖数: 493
6
bitmap index on date field, if date is really timestamp, that is abusing
bitmap index.
B*****g
发帖数: 34098
7
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
: 想请教一下实际设计中是怎么做的?谢谢!

j*****n
发帖数: 1781
8
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

w*******e
发帖数: 1622
9
恩, 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.

B*****g
发帖数: 34098
10
不明白。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.

相关主题
求助:找出现2次及以上的记录SQL 2008 Create Index vs Rebuild Index (Alter Index)
indexing就是设置primary key吗?log shipping 问题
请教 sql server index问题SQL 2000 create index 問題
进入Database版参与讨论
j*****n
发帖数: 1781
11
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

j*****n
发帖数: 1781
12
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

B*****g
发帖数: 34098
13
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.

j*****n
发帖数: 1781
14
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.

gy
发帖数: 620
15
我纯属抬杠哈...
即使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.

gy
发帖数: 620
16
恩, 所以建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.

1 (共1页)
进入Database版参与讨论
相关主题
为啥RDBMS只用一个Index? (转载)Oracle Group and Index question
MySQL 5.0 cluster question求助:找出现2次及以上的记录
INSERT or UPDATE, which is faster?indexing就是设置primary key吗?
为什么微软专家给一个4x5的只读小表建64个Index(完全相同的)?请教 sql server index问题
如何决定indexSQL 2008 Create Index vs Rebuild Index (Alter Index)
more q: how to make database size smallerlog shipping 问题
When should I reorganize Index/Rebuuild Index?SQL 2000 create index 問題
被人鄙视了最近找工作的经验 SQL DBA更新
相关话题的讨论汇总
话题: index话题: accountid话题: clustered话题: date话题: sql