RE: Indices en tablas

From: Lazaro Ruben Garcia Martinez <lgarciam(at)vnz(dot)uci(dot)cu>
To: Jaime Casanova <jaime(at)2ndquadrant(dot)com>, Pedro PG <pedropg(at)outlook(dot)com>
Cc: "pgsql-es-ayuda(at)postgresql(dot)org" <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: RE: Indices en tablas
Date: 2013-10-29 16:18:56
Message-ID: 294D3D02D5E18D42827B2ECFEADEB688BA00F4BED7@mx-interno.vnz.uci.cu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Si la tabla del muchos, en este caso ruta, no es muy grande, no creo que un índice en la relación pueda ser necesario, pues con poco volumen de datos una búsqueda secuencial podría ir muy bien. Además según veo esa tabla solo tiene dos campos de tipo integer, o sea que en un bloque de datos que normalmente es de 8192 bytes cabría una gran cantidad de tuplas teniendo en cuenta que integer ocupa solo 4 bytes de almacenamiento, además de lo que comenta Jaime, pues si el índice apenas es usado, solo te ocupará espacio. Puedes ejecutar un explain de la consulta primero sin índice y luego con índice a ver cuales son los resultados y podrás tomar una decisión.

Saludos a todos.
________________________________________
De: pgsql-es-ayuda-owner(at)postgresql(dot)org [pgsql-es-ayuda-owner(at)postgresql(dot)org] En nombre de Jaime Casanova [jaime(at)2ndquadrant(dot)com]
Enviado el: martes, 29 de octubre de 2013 10:40
Para: Pedro PG
CC: pgsql-es-ayuda(at)postgresql(dot)org
Asunto: Re: [pgsql-es-ayuda] Indices en tablas

2013/10/29 Pedro PG <pedropg(at)outlook(dot)com>:
> Buen día lista, tengo una consulta, tengo dos tablas (el típico maestro -
> detalle).
>
> Tabla: lugar (id serial, nombre varchar) -> id tiene un indice HASH.
> Tabla: ruta (id serial, idlugar integer) -> id tiene un indice HASH, ¿es
> necesario crear un indice en idlugar? y en el caso la respuesta sea si como
> es que deberia hacerlo.
>

No tengo la menor idea de si deberías crear ese índice. Para saber eso
necesitaríamos saber: 1) cuantos registros tendrá la tabla 2) que tan
frecuentemente se consultará por el campo idlugar y 3) que tan
selectivas serán dichas consultas.

Lo que si se, es que no deberías estar usando índices HASH

http://www.postgresql.org/docs/current/static/indexes-types.html
"""
Caution

Hash index operations are not presently WAL-logged, so hash indexes
might need to be rebuilt withREINDEX after a database crash if there
were unwritten changes. Also, changes to hash indexes are not
replicated over streaming or file-based replication after the initial
base backup, so they give wrong answers to queries that subsequently
use them. For these reasons, hash index use is presently discouraged.
"""

--
Jaime Casanova www.2ndQuadrant.com
Professional PostgreSQL: Soporte 24x7 y capacitación
Phone: +593 4 5107566 Cell: +593 987171157

-
Enviado a la lista de correo pgsql-es-ayuda (pgsql-es-ayuda(at)postgresql(dot)org)
Para cambiar tu suscripción:
http://www.postgresql.org/mailpref/pgsql-es-ayuda

Fin a la injusticia, LIBERTAD AHORA A NUESTROS CINCO COMPATRIOTAS QUE SE ENCUENTRAN INJUSTAMENTE EN PRISIONES DE LOS EEUU!
http://www.antiterroristas.cu
http://justiciaparaloscinco.wordpress.com

Fin a la injusticia, LIBERTAD AHORA A NUESTROS CINCO COMPATRIOTAS QUE SE ENCUENTRAN INJUSTAMENTE EN PRISIONES DE LOS EEUU!
http://www.antiterroristas.cu
http://justiciaparaloscinco.wordpress.com

-
Enviado a la lista de correo pgsql-es-ayuda (pgsql-es-ayuda(at)postgresql(dot)org)
Para cambiar tu suscripción:
http://www.postgresql.org/mailpref/pgsql-es-ayuda

In response to

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Lazaro Ruben Garcia Martinez 2013-10-29 16:19:19 RE: Indices en tablas
Previous Message Alvaro Herrera 2013-10-29 15:48:21 Re: Indices en tablas