First, I am a complete novice when it comes to databases, but have been given the task to speed up queries on a large set of data. (Hundreds of millions of records) The current implementation is a very simple data warehouse that was created long ago in Oracle. The existing table has no primary key but each record is unique. The table is indexed by the first two columns listed below.
The data itself is fairly simple:
- device – there are multiple devices with a unique number indicator
- data generation time – each device generates a set of data multiple times a day at different, random times. Each data set covers multiple days. Sample times for individual data points in the set can be up to every second. For times prior to the data generation time, these are measured results. For times after the data generation time, these are the device’s prediction of what the data will be. Queries are often pulled for a full day that compare measured verses predicted data for a given device (e.g. how well did the device predict future needs)
- Date/Time of the data points
- Data point 1
- Data point 2
. . . Data point 23
The major types of queries are:
- Give me the latest data generated by a device
- Give me all the data for a device for a given day (as previously described above.)
- Give me the data generation times for a device on a given day
My idea to speed up queries would be to split the table up into two tables as follows:
MetaData Table (each of the first 3 will be indexed)
- device
- data generation time
- day – This would be a new, indexed data point
- Primary Key – a number with the device number, data generation time (141230073205 – for 2014 Dec 30 07:32:05), and day (150102 – for 2015 Jan 02)
Data Points Table (There will be 10s of thousands of these for each entry in the MetaData table above)
- Foreign Key – that points to the Primary Key in the above MetaData table for which this particular point is valid
- Date/Time of the data points
- Data point 1
- Data point 2 . . . Data point 23
So, long story short (too late!):
- Is this a valid approach to speeding up queries?
- Is there a better way to organize the data?
- What other things can I do to cut down on the query times?
- Any sqlplus coding tips would also be greatly appreciated.
CREATE INDEX SEARCH_ON_DATE ON TABLE (TRUNC(DP_DATETIME), DEVICE);