Note that there are some explanatory texts on larger screens.

plurals
  1. POSlow query time in postgresql when UTC milliseconds is stored as bigint
    primarykey
    data
    text
    <p>We are migrating from a time series database (ECHO historian) to a open source database basically due to price factor. Our choice was PostgreSQL as there are no open source time series database. What we used to store in the ECHO was just time and value pairs. Now here is the problem. The table that I created in postgre consists of 2 columns. First is of "bigint" type to store the time in UTC milliseconds(13 digit number) and second is the value whose data type is set to "real" type. I had filled up around 3.6 million rows (Spread across a time range of 30 days) of data and when I query for a small time range (say 1 day) the query takes 4 seconds but for the same time range in ECHO the response time is 150 millisecs!. This is a huge difference. Having a bigint for time seems to be the reason for the slowness but not sure. Could you please suggest how the query time can be improved. I also read about using the data type "timestamp" and "timestamptz" and looks like we need to store the date and time as regular format and not UTC seconds. Can this help to speed up my query time? </p> <p>Here is my table definition :</p> <pre><code> Table "public. MFC2 Flow_LCL " Column | Type | Modifiers | Storage | Stats target | Description ----------+--------+-----------+---------+--------------+------------- the_time | bigint | | plain | | value | real | | plain | | Indexes: "MFC2 Flow_LCL _time_idx" btree (the_time) Has OIDs: no </code></pre> <p>Currently i am storing the time in UTC milliseconds (using bigint). The challenge here is there could be duplicate time value pairs. </p> <p>This is the query i am using (called through a simple API which will pass table name, start and end time)</p> <pre><code>PGresult *res; int rec_count; std::string sSQL; sSQL.append("SELECT * FROM "); sSQL.append(" \" "); sSQL.append(table); sSQL.append(" \" "); sSQL.append(" WHERE"); sSQL.append(" time &gt;= "); CString sTime; sTime.Format("%I64d",startTime); sSQL.append(sTime); sSQL.append(" AND time &lt;= "); CString eTime; eTime.Format("%I64d",endTime); sSQL.append(eTime); sSQL.append(" ORDER BY time "); res = PQexec(conn, sSQL.c_str()); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload