|
尝试在PostgreSQL上重新创建我的SQL Server数据库。一切正常,除了我找不到如何重新创建此索引:8 k& w& L- {& h# A8 x
USE [mytablename]
, C9 t( f& ?/ n2 I1 m- b. k1 R9 p, qGO " x$ k5 A: e+ x: e7 T
CREATE NONCLUSTERED INDEX [myindex] 6 n: s+ M& f$ v# _& J, u8 s
ON [dbo].[mytablename] ([col1],[col2]) 2 V/ r7 K; Q5 V- R6 B, h
INCLUDE ([col3],[col4])
8 k6 c6 \5 K! \$ ^3 v/ u. n; hGO5 M2 D6 b; ~0 N8 R6 l/ T( l' @. n
将非常感谢您的帮助。0 M- h5 U* h, i0 f
阿列克谢
/ C" M n( p8 l% `- [5 k( U更新:
! l) b# k3 M6 |: Shttp://img38.imageshack.us/img38/1071/89013974.png这是db结构star. `# {1 f, M$ {3 A* B7 ~
+ eav8 e w+ \2 p; Z+ m! v3 [) S. y1 `
,只有一个查询, n V. T# U( |/ `. b1 T: ?
SELECT this_.id as id0_0_,
* W/ P- g. p3 `! m- vthis_.device_id as device2_0_0_, 1 W# I% E" |7 t
this_.time_id as time3_0_0_, / w& A6 P3 t1 u/ w- s
this_.gps_detail_id as gps4_0_0_ ; O1 [9 Q1 N! G
FROM [scoutserver_data].[dbo].[DataMessage] this_ ) j9 q. [" E U( R$ M
WHERE this_.time_id = 65536 and this_.device_id = 32768
& n1 ]4 a7 I' _1 a3 k7 M; i' Z也许这不是最佳的atm。我也正在努力。也许是这样的
* e4 V7 f. G* e8 |( r+ c4 q0 O( SSELECT * FROM [scoutserver_data].[dbo].[TimeDimension]
/ W/ M5 k& j/ c, `" E" [$ C INNER JOIN ([scoutserver_data].[dbo].[DeviceDimension]
7 r3 s2 Z9 ^& |4 s INNER JOIN [scoutserver_data].[dbo].[DataMessage]
* t# S' A# G5 ?7 B% RON [DeviceDimension].[device_id] =[DataMessage].[device_id]) % H- D, \" J- N4 E- U; R
ON [TimeDimension].[time_id] = [DataMessage].[time_id] ! N9 `9 f+ _( V
WHERE DeviceDimension.serial_id='2' AND TimeDimension.Day=15 AND TimeDimension.Year=2009" P$ M* M' g6 o& z3 Q7 j2 S. I
任何提示欢迎=) q, V" `4 ?1 V% _ x
/ ^8 |6 F- S% `( I3 L$ r+ e$ d解决方案:! b! a7 |$ n# Z
! X5 L( F' l7 h- W! {
3 n/ z4 T- p9 s* b5 Z/ k/ V& f4 x5 f8 Z8 C4 J U3 F
CREATE INDEX myindex ON mytablename (co1l, col2, col3, col4)( j) }* J. m1 w3 y
PostgreSQL 不支持群集索引或覆盖索引。9 w8 B2 X+ {" U3 l N
更新:
# q3 T, s9 `# ^ f; ?对于此查询,您确实需要创建建议的索引:
, w) m& [5 s5 q" \9 W9 S" ZSELECT this_.id as id0_0_, ) r* r' g4 s& Z' s# p( L
this_.device_id as device2_0_0_,
0 H# p. h/ `* q this_.time_id as time3_0_0_, & ~! \/ X7 h; W# k2 a
this_.gps_detail_id as gps4_0_0_ / c* A0 M9 H \% B# O2 ?
FROM DataMessage this_
# w, ]9 ]' c. t( |/ j/ \/ C" IWHERE this_.time_id = 65536
% F& N9 a& t- M8 b" L AND this_.device_id = 32768
3 g( K5 E, _7 Q) }3 {, lCREATE INDEX ix_datamessage_time_device_id_detail ON datamessage (time_id, device_id, id, gps_detail_id)
& X2 t3 L1 A( a( o但是,您的表格对我而言似乎过于规范化了。
% t: w( p4 y5 H4 s. i& o您可以INT在表的单个字段中保留年,月和日。这将节省您的加入。
. H& H+ P6 y6 b! y/ n! \如果其中一个很少被链接到(通常设置为),或者可以在多个数据消息之间共享GPS详细记录,则可能会有一个保留点,DataMessage并GpsDetails放在单独的表中。GpsDetails``DataMessage``gps_details_id``NULL$ _2 c6 N. e+ k+ e
并非如此,最好将GPS详细信息移到数据消息表中。 |
|