Subject | LEFT JOIN AND ORDER BY |
---|---|
Author | aleskahanek |
Post date | 2004-11-18T14:10:09Z |
Hi,
I would like to ask what to do with the following query to make it
more quicker. There is a table PERSON with approx 300000 records and
table COMPANY (1000 records)
CREATE TABLE PERSON (
PER_ID BIGINT NOT NULL,
COM_ID BIGINT,
LNAME VARCHAR(25) COLLATE PXW_CSY);
PER_ID is primary key
COM_ID is foreign key to table COMPANY
LNAME has ascending index created
CREATE TABLE COMPANY (
COM_ID BIGINT NOT NULL,
COM_NAME VARCHAR(100) COLLATE PXW_CSY);
COM_ID is primary index
This query takes about 20 seconds
SELECT PERSON.LNAME, COMPANY.COM_NAME
FROM PERSON
LEFT JOIN COMPANY ON PERSON.COM_ID=COMPANY.COM_ID
ORDER BY PERSON.LNAME
PLAN SORT (JOIN (PERSON NATURAL,COMPANY INDEX (RDB$PRIMARY4)))
while this returns almost immediately (without sorting)
SELECT PERSON.LNAME
FROM PERSON
LEFT JOIN COMPANY ON PERSON.COM_ID=COMPANY.COM_ID
Why Firebird does not use the LNAME index for table PERSON?
I need to use LEFT JOIN and also order the result set according to
LNAME. In real application the tables have more columns of course.
Any hints are very apprecitated.
Thanks
Ales
I would like to ask what to do with the following query to make it
more quicker. There is a table PERSON with approx 300000 records and
table COMPANY (1000 records)
CREATE TABLE PERSON (
PER_ID BIGINT NOT NULL,
COM_ID BIGINT,
LNAME VARCHAR(25) COLLATE PXW_CSY);
PER_ID is primary key
COM_ID is foreign key to table COMPANY
LNAME has ascending index created
CREATE TABLE COMPANY (
COM_ID BIGINT NOT NULL,
COM_NAME VARCHAR(100) COLLATE PXW_CSY);
COM_ID is primary index
This query takes about 20 seconds
SELECT PERSON.LNAME, COMPANY.COM_NAME
FROM PERSON
LEFT JOIN COMPANY ON PERSON.COM_ID=COMPANY.COM_ID
ORDER BY PERSON.LNAME
PLAN SORT (JOIN (PERSON NATURAL,COMPANY INDEX (RDB$PRIMARY4)))
while this returns almost immediately (without sorting)
SELECT PERSON.LNAME
FROM PERSON
LEFT JOIN COMPANY ON PERSON.COM_ID=COMPANY.COM_ID
Why Firebird does not use the LNAME index for table PERSON?
I need to use LEFT JOIN and also order the result set according to
LNAME. In real application the tables have more columns of course.
Any hints are very apprecitated.
Thanks
Ales