Trying to recreate my SQL Server database on PostgreSQL. Everything is ok except I can't find how to recreate this index:
USE [mytablename]
GO
CREATE NONCLUSTERED INDEX [myindex]
ON [dbo].[mytablename] ([col1],[col2])
INCLUDE ([col3],[col4])
GO
Will be very grateful for help.
Alexey
Update:
http://img38.imageshack.us/img38/1071/89013974.png here is db structure star+eav
there is only one query
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
Maybe it is not optimal atm. And im working on it also. Maybe something like this
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
Any hints welcome =)
Included columns can be varchar (max), nvarchar(max) , varbinary(max) or XML data types, that you cannot add it as index keys. Computed columns can also be used as included columns.
In the included columns the storage only happens on the leaf level of the index, contrary to the key column of an index. The key column of an index is stored at all levels. The non-key columns don't have the same limitations as the index key columns in terms of the data type.
The reason for this is that when you apply a clustered columnstore index to a table, SQL Server changes the physical storage of the table to columns. As such, all columns are included in the clustered columnstore index.
The Include Clause. The include clause allows us to make a distinction between columns we would like to have in the entire index (key columns) and columns we only need in the leaf nodes ( include columns). That means it allows us to remove columns from the non-leaf nodes if we don't need them there.
CREATE INDEX myindex ON mytablename (co1l, col2, col3, col4)
PostgreSQL
does not support clustered or covering indexes.
Update:
For this query, you'll need to create the suggested index indeed:
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 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)
However, your tables seem to be over-normalized to me.
You can keep year, month and day in a single INT
field in your table. This will save you a join.
There might be the point of keeping DataMessage
and GpsDetails
in separate tables if either GpsDetails
are rarely linked to the DataMessage
(this is, gps_details_id
is often set to NULL
), or a GPS details record can be shared between multiple data messages.
It it's not, it will be better to move the GPS details into the data messages table.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With