加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

PostgreSQL模拟SQL Server索引(包括列)

发布时间:2020-12-13 16:14:39 所属栏目:百科 来源:网络整理
导读:试图在PostgreSQL上重新创建我的SQL Server数据库.一切都很好,除了我找不到如何重新创建这个索引: USE [mytablename] GO CREATE NONCLUSTERED INDEX [myindex] ON [dbo].[mytablename] ([col1],[col2]) INCLUDE ([col3],[col4]) GO 将非常感谢您的帮助. 阿
试图在PostgreSQL上重新创建我的SQL Server数据库.一切都很好,除了我找不到如何重新创建这个索引:
USE [mytablename]  
GO  
CREATE NONCLUSTERED INDEX [myindex]  
ON [dbo].[mytablename] ([col1],[col2])  
INCLUDE ([col3],[col4])  
GO

将非常感谢您的帮助.

阿列克谢

更新:

http://img38.imageshack.us/img38/1071/89013974.png这里是db structure star eav
只有一个查询

SELECT this_.id as id0_0_,this_.device_id as device2_0_0_,this_.time_id as time3_0_0_,this_.gps_detail_id as gps4_0_0_   
FROM [scoutserver_data].[dbo].[DataMessage]  this_   
WHERE this_.time_id = 65536 and this_.device_id = 32768

也许它不是最佳的atm.我正在研究它.也许是这样的

SELECT * FROM [scoutserver_data].[dbo].[TimeDimension]   
  INNER JOIN ([scoutserver_data].[dbo].[DeviceDimension]   
  INNER JOIN  [scoutserver_data].[dbo].[DataMessage]   
ON [DeviceDimension].[device_id] =[DataMessage].[device_id])  
ON [TimeDimension].[time_id] = [DataMessage].[time_id]  
WHERE DeviceDimension.serial_id='2' AND TimeDimension.Day=15 AND TimeDimension.Year=2009

任何提示欢迎=)

CREATE INDEX myindex ON mytablename (co1l,col2,col3,col4)

PostgreSQL不支持聚簇或覆盖索引.

更新:

对于此查询,您需要确实创建建议的索引:

SELECT  this_.id as id0_0_,this_.gps_detail_id as gps4_0_0_   
FROM    DataMessage this_   
WHERE   this_.time_id = 65536
        AND this_.device_id = 32768

CREATE INDEX ix_datamessage_time_device_id_detail ON datamessage (time_id,device_id,id,gps_detail_id)

但是,你的表似乎对我来说过度标准化了.

您可以将年,月和日保存在表中的单个INT字段中.这将为您节省一次加入.

如果GpsDetails很少链接到DataMessage(这是gps_details_id通常设置为NULL),或者可以在多个数据消息之间共享GPS详细信息记录,则可能需要将DataMessage和GpsDetails保存在单独的表中.

事实并非如此,将GPS细节移动到数据消息表中会更好.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读