Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> comp.databases.theory -> Re: Query execution for intervals

Re: Query execution for intervals

From: -CELKO- <jcelko212_at_earthlink.net>
Date: 5 Feb 2006 08:22:34 -0800
Message-ID: <1139156554.415774.101630@z14g2000cwz.googlegroups.com>


CREATE TABLE Events
(event_name CHAR(10) NOT NULL,
 start_date DATE NOT NULL,
 end_date DATE, -- null means active
 CHECK (start_date <= end_date),
  PRIMARY KEY (start_date, event_name));

>> Is it possible for the DBMS to execute this query faster than linear time? <<

Yes. Most products will use a tree index for the primary key. Since the start date is the first column in that index, it will be searchable.

As a matter of style, I would write:

SELECT ..
  FROM Events
WHERE :my_date BETWEEN start_date AND COALESCE (end_date, CURRENT_TIMESTAMP); if the response is still too slow, try putting the end_date into the PRIMARY KEY to get a covering index. Received on Sun Feb 05 2006 - 10:22:34 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US