boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - SQL fast search in a 10 million records table (转载)
相关主题
Help! A cluster method in SQL
SQL find distinct values in large table
SQL multiply all values of a column in table (转载)
SQL combine two columns from two different tables no shared (转载)
Table Merge (SQL Server)
mysql maximum columns <=1000?
SQL 2000 create index 問題
初级问题
help about SQL for ACCESS
sql question
相关话题的讨论汇总
话题: value话题: search话题: column话题: table话题: sql
进入Database版参与讨论
1 (共1页)
l******9
发帖数: 579
1
【 以下文字转载自 JobHunting 讨论区 】
发信人: light009 (light009), 信区: JobHunting
标 题: SQL fast search in a 10 million records table
发信站: BBS 未名空间站 (Thu Jul 24 23:26:56 2014, 美东)
I need to do a fast search in a column with floating point numbers in a
table of SQL server 2008 R2 on Win 7.
the table has 10 million records.
e.g.
Id value
532 937598.32421
873 501223.3452
741 9797327.231
ID is primary key, I need o do a search on "value" column for a given value
such that I can find the 5 closest points to the given point in the table.
The closeness is defined as the absolute value of the difference between the
given value and column value.
The smaller value, the closer.
I would like to use binary search.
I want to set an unique index on the value column.
But, I am not sure whether the table will be sorted every time when I search
the given value in the column ?
Or, it only sorts the table one time because I have set the value column as
unique index ?
Are there better ways to do this search ?
Any help would be appreciated.
thanks
B*****g
发帖数: 34098
2
这个值其实就是
比你输入值大的最小值 和 比你输入值小的最大值
中的一个

【在 l******9 的大作中提到】
: 【 以下文字转载自 JobHunting 讨论区 】
: 发信人: light009 (light009), 信区: JobHunting
: 标 题: SQL fast search in a 10 million records table
: 发信站: BBS 未名空间站 (Thu Jul 24 23:26:56 2014, 美东)
: I need to do a fast search in a column with floating point numbers in a
: table of SQL server 2008 R2 on Win 7.
: the table has 10 million records.
: e.g.
: Id value
: 532 937598.32421

o**a
发帖数: 1315
3
进来学习。
Binary search是说用B tree index?
ID是primary key的话,在这个search key上的index通常是clustered and ordered.
可以在value上建secondary nonclustered index,怎么order应该可以自己指定吧?
另外,value是不是一个nonunique search key。
能不能考虑用composite search key?

【在 l******9 的大作中提到】
: 【 以下文字转载自 JobHunting 讨论区 】
: 发信人: light009 (light009), 信区: JobHunting
: 标 题: SQL fast search in a 10 million records table
: 发信站: BBS 未名空间站 (Thu Jul 24 23:26:56 2014, 美东)
: I need to do a fast search in a column with floating point numbers in a
: table of SQL server 2008 R2 on Win 7.
: the table has 10 million records.
: e.g.
: Id value
: 532 937598.32421

B*A
发帖数: 83
4
这不是数据库的思路。
你可以认为所有的数据都是有序的,可是数据库并不能快速的找到第五百万个数据,以
及第二百五十万,等等。
利用数据库功能的做法似乎是
Select top 5
From (select id, abs(value-your number ) from table
Order by abs(value-your number ))

★ 发自iPhone App: ChineseWeb 8.1

【在 l******9 的大作中提到】
: 【 以下文字转载自 JobHunting 讨论区 】
: 发信人: light009 (light009), 信区: JobHunting
: 标 题: SQL fast search in a 10 million records table
: 发信站: BBS 未名空间站 (Thu Jul 24 23:26:56 2014, 美东)
: I need to do a fast search in a column with floating point numbers in a
: table of SQL server 2008 R2 on Win 7.
: the table has 10 million records.
: e.g.
: Id value
: 532 937598.32421

o**a
发帖数: 1315
5
数据库中的记录以文件形式存储在磁盘上,physically其很少是sequentially stored
的,所以才用index来给其logically组织一下,增加random access的效率,是这样吧。

【在 B*A 的大作中提到】
: 这不是数据库的思路。
: 你可以认为所有的数据都是有序的,可是数据库并不能快速的找到第五百万个数据,以
: 及第二百五十万,等等。
: 利用数据库功能的做法似乎是
: Select top 5
: From (select id, abs(value-your number ) from table
: Order by abs(value-your number ))
:
: ★ 发自iPhone App: ChineseWeb 8.1

B*A
发帖数: 83
6
你是对的。我是针对他的提问:如果有Index的话,是不是每次仍要再sort。如果要做
select
order By index column 数据库可不需
要做sort. 直接顺着index往下读就好了

stored
吧。
★ 发自iPhone App: ChineseWeb 8.1
★ 发自iPhone App: ChineseWeb 8.1
★ 发自iPhone App: ChineseWeb 8.1
★ 发自iPhone App: ChineseWeb 8.1

【在 o**a 的大作中提到】
: 数据库中的记录以文件形式存储在磁盘上,physically其很少是sequentially stored
: 的,所以才用index来给其logically组织一下,增加random access的效率,是这样吧。

1 (共1页)
进入Database版参与讨论
相关主题
sql question
Help on Sql server huge table performance
请教SQL server的一个programming的问题,谢谢
SQL Conditional Select
SQL问题请教: add one more column
SQL Server table variable 的一个问题请教。
In MySQL, 如何在procedure里create trigger?谢谢了?
很弱的Oracle问题
SQL Server Trigger on System Base Table or Catalog View
一个single table 的 SQL QUERY
相关话题的讨论汇总
话题: value话题: search话题: column话题: table话题: sql