pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Index
5+ messages / 5 participants
[nested] [flat]

* Index
@ 1999-01-28 23:40  Lucas Szczepankowski <lucas@paynet.net>
  0 siblings, 0 replies; 5+ messages in thread

From: Lucas Szczepankowski @ 1999-01-28 23:40 UTC (permalink / raw)
  To: pgsql-general

Can anyone tell me if there is a way to create an index in descending order in Postgresql?
Thanks
Lucas Szczepankowski

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Index
@ 2001-06-12 17:44  Dmitry Andrianov <dimas@dataart.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Dmitry Andrianov @ 2001-06-12 17:44 UTC (permalink / raw)
  To: pgsql-general


Hi.

I just installed PG 7.1.2, created a table, consisting of single
varchar(32) column 'name' and filled it with ~3M records (real last name
from our user database). After that i have created index on this column
and VACUUM ANALYZEd the table.

test=# \d lnames
                Table "lnames"
 Attribute |         Type          | Modifier 
-----------+-----------------------+----------
 name      | character varying(32) | 
Index: idx_main

test=# \d idx_main
         Index "idx_main"
 Attribute |         Type          
-----------+-----------------------
 name      | character varying(32)
btree



test=# EXPLAIN SELECT * FROM lnames WHERE name='ivanov';
NOTICE:  QUERY PLAN:

Index Scan using idx_main on lnames  (cost=0.00..4847.52 rows=1271
width=12)

EXPLAIN


I think, PG should respond instantly on queries like "SELECT * FROM
lnames WHERE name='ivanov'". And it does unless there are many records
with the same value. But in case when there are about 3000 records with
name='ivanov', it takes about a half a minute for Postgres before I can
even see a first row.

Why is that?

Also interesting:

SELECT COUNT(*) FROM lnames WHERE name='ivanov';

this query takes about 20 seconds on table without an index
(sequentional scan) and 40 seconds (2 times more!) after index has been
built and analyzed.

Could anybody explain me what i'm doing wrong, please?

Thanks in advance.

Regards,
Dmitry Andrianov






^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Index
@ 2019-10-25 05:34  Sonam Sharma <sonams1209@gmail.com>
  0 siblings, 2 replies; 5+ messages in thread

From: Sonam Sharma @ 2019-10-25 05:34 UTC (permalink / raw)
  To: pgsql-general

I have created indexes with certain set of columns. Now I want to remove
one of the column and add new column. Can this done without dropping the
index?

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Index
@ 2019-10-25 11:13  Luca Ferrari <fluca1978@gmail.com>
  parent: Sonam Sharma <sonams1209@gmail.com>
  1 sibling, 0 replies; 5+ messages in thread

From: Luca Ferrari @ 2019-10-25 11:13 UTC (permalink / raw)
  To: Sonam Sharma <sonams1209@gmail.com>; +Cc: pgsql-general

On Fri, Oct 25, 2019 at 7:35 AM Sonam Sharma <sonams1209@gmail.com> wrote:
>
> I have created indexes with certain set of columns. Now I want to remove one of the column and add new column. Can this done without dropping the index?


If you are going to rename the column the answer is yes.
If you are going to drop the column that would also invalidate and
drop the index.
If you are changing the data type the index should remain in place.

See <https://www.postgresql.org/docs/12/sql-altertable.html; in
particular paragraph about 'DROP COLUMN' and 'SET DATA TYPE'.

Luca





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Index
@ 2019-10-25 11:31  Ravi Krishna <sr_krishna@aol.com>
  parent: Sonam Sharma <sonams1209@gmail.com>
  1 sibling, 0 replies; 5+ messages in thread

From: Ravi Krishna @ 2019-10-25 11:31 UTC (permalink / raw)
  To: Sonam Sharma <sonams1209@gmail.com>; +Cc: pgsql-general

> 
> I have created indexes with certain set of columns. Now I want to remove one of the column and add new column. Can this done without dropping the index?
> 

If you intent is to avoid taking that table offline while the index is being built, you can do this:

1. create index concurrently on the new set of columns
2. once (1) done drop old index






^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2019-10-25 11:31 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-01-28 23:40 Index Lucas Szczepankowski <lucas@paynet.net>
2001-06-12 17:44 Index Dmitry Andrianov <dimas@dataart.com>
2019-10-25 05:34 Index Sonam Sharma <sonams1209@gmail.com>
2019-10-25 11:13 ` Luca Ferrari <fluca1978@gmail.com>
2019-10-25 11:31 ` Ravi Krishna <sr_krishna@aol.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox