Note that there are some explanatory texts on larger screens.

plurals
  1. POQuery plan for database table containing trillions of records
    primarykey
    data
    text
    <p>I have a big table containing trillions of records of the following schema (Here serial no. is the key):</p> <pre><code> MyTable Column | Type | Modifiers ----------- +--------------------------+----------- serial_number | int | name | character varying(255) | Designation | character varying(255) | place | character varying(255) | timeOfJoining | timestamp with time zone | timeOfLeaving | timestamp with time zone | </code></pre> <p>Now I want to fire queries of the form given below on this table:</p> <pre><code>select place from myTable where Designation='Manager' and timeOfJoining&gt;'1930-10-10' and timeOfLeaving&lt;'1950-10-10'; </code></pre> <p>My aim is to achieve fast query execution times. Since, I am designing my own database from scratch, therefore I have the following options. Please guide me as to which one of the two options will be faster.</p> <ol> <li><p>Create 2 separate table. Here, table1 contains the schema (serial_no, name, Designation, place) and table 2 contains the schema (serial_no, timeOfJoining, timeOfLeaving). And then perform a merge join between the two tables. Here, serial_no is the key in both the tables</p></li> <li><p>Keep one single table MyTable. And run the following plan: Create an index Designation_place_name and using the Designation_place_name index, find rows that fit the index condition relation = 'Manager'(The rows on disc are accessed randomly) and then using the filter function keep only rows that match the timeOfJoining criteria.</p></li> </ol> <p>Please help me figure out which one will be faster. It'll be great if you could also tell me the respective pros and cons.</p> <p>EDIT: I intend to use my table as read-only.</p>
    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.
 

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