Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select version();
- version
- ---------------------------------------------------------------------------------------------------------
- PostgreSQL 11.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28), 64-bit
- (1 row)
- drop table if exists tab1;
- DROP TABLE
- create table tab1 ( r_object_id char(16) primary key, dcmi_title varchar(250) );
- CREATE TABLE
- create index tab1__dcmi_title on tab1 ( lower(dcmi_title) );
- CREATE INDEX
- create or replace function custom_lower(s text) RETURNS text as $$
- SELECT LOWER(s);
- $$ LANGUAGE sql;
- CREATE FUNCTION
- drop table if exists tab2;
- DROP TABLE
- create table tab2 ( r_object_id char(16) primary key, dcmi_title varchar(250) );
- CREATE TABLE
- create index tab2__dcmi_title on tab2 ( custom_lower(dcmi_title) );
- CREATE INDEX
- explain SELECT * FROM ( SELECT r_object_id, lower(dcmi_title) s_dcmi_title from tab1 ) t WHERE s_dcmi_title = 'all aboard 1 poster pack'
- ;
- QUERY PLAN
- -------------------------------------------------------------------------------
- Index Scan using tab1__dcmi_title on tab1 (cost=0.14..8.16 rows=1 width=100)
- Index Cond: (lower((dcmi_title)::text) = 'all aboard 1 poster pack'::text)
- (2 rows)
- explain SELECT * FROM ( SELECT r_object_id, lower(dcmi_title) calculated_col from tab1 WHERE lower(dcmi_title) = 'all aboard 1 poster pack' ) t
- ;
- QUERY PLAN
- -------------------------------------------------------------------------------
- Index Scan using tab1__dcmi_title on tab1 (cost=0.14..8.16 rows=1 width=100)
- Index Cond: (lower((dcmi_title)::text) = 'all aboard 1 poster pack'::text)
- (2 rows)
- explain SELECT * FROM ( SELECT r_object_id, custom_lower(dcmi_title) calculated_col from tab2 WHERE custom_lower(dcmi_title) = 'all aboard 1 poster pack' ) t
- ;
- QUERY PLAN
- -------------------------------------------------------------------------------
- Index Scan using tab2__dcmi_title on tab2 (cost=0.14..8.16 rows=1 width=100)
- Index Cond: (lower((dcmi_title)::text) = 'all aboard 1 poster pack'::text)
- (2 rows)
- explain SELECT * FROM ( SELECT r_object_id, custom_lower(dcmi_title) s_dcmi_title from tab2 ) t WHERE s_dcmi_title = 'all aboard 1 poster pack'
- ;
- QUERY PLAN
- ---------------------------------------------------------------
- Subquery Scan on t (cost=0.00..13.25 rows=1 width=100)
- Filter: (t.s_dcmi_title = 'all aboard 1 poster pack'::text)
- -> Seq Scan on tab2 (cost=0.00..11.62 rows=130 width=100)
- (3 rows)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement