Optimized Select Statement - Mailing list pgsql-general

From Yan Cheng Cheok
Subject Optimized Select Statement
Date
Msg-id 1893.70905.qm@web65716.mail.ac4.yahoo.com
Whole thread Raw
In response to Re: PostgreSQL Write Performance  (Simon Riggs <simon@2ndQuadrant.com>)
Responses Re: Optimized Select Statement  (Ivan Sergio Borgonovo <mail@webthatworks.it>)
List pgsql-general
I am having the table with 1 million rows.

I know there can be multiple "YanChengCHEOK". But in certain situation, I will be only interested in 1 "YanChengCHEOK".

I try to perform SELECT query.

SemiconductorInspection=# SELECT measurement_type_id FROM measurement_type WHERE measurement_type_name='YanChengCHEOK';
 measurement_type_id
---------------------
                   1
(1 row)
Time: 331.057 ms

I try to have it in stored procedures.

DECLARE
    _measurement_type_id int8;
BEGIN
    SELECT measurement_type_id INTO _measurement_type_id FROM measurement_type WHERE
measurement_type_name='YanChengCHEOK';
    RAISE NOTICE '%', _measurement_type_id;
    return 1;
end;

It tools me only 1.018ms

High chance that PostgreSQL stop looking further, when it found that the variable int8 had been fill in with at most 1
value.

Without using stored procedure, how can I send a SQL statement to PostgreSQL, to tell it that I need only 1
measurement_type_id,to speed up the SELECT speed. 

Thanks and Regards
Yan Cheng CHEOK






pgsql-general by date:

Previous
From: Aleksey Tsalolikhin
Date:
Subject: WAL archiving is stuck on an old file that was deleted -- how to get it going again? (8.4.2)
Next
From: Ivan Sergio Borgonovo
Date:
Subject: Re: Optimized Select Statement