2013/6/25 William Diaz Pabón <[email protected]>: > > Donde tengo una tabla con un campo estado que tiene esta constraint > > CHECK (estado::text = 'ACTIVO'::text OR estado::text = 'INACTIVO'::text OR > estado::text = 'PAGADO'::text OR estado::text = 'CANJE'::text OR > estado::text = 'LIQUIDADO'::text OR estado::text = 'CONVENIO'::text OR > estado::text = 'REFINANCIADO'::text OR estado::text = 'PRESCRITO'::text), >
Uh! esto esta bastante feo... quizá quieras ver sobre los enumerados: http://www.postgresql.org/docs/8.4/static/datatype-enum.html > cuando hago un select donde el where hace estado = 'INACTIVO' y hago un > explain query me indica que esta usando el indice. > > pero cuando hago estado = 'ACTIVO' y hago un explain query me indica que > NO esta usando el indice. y me dice que hay 158 mil filas. > > como se hace para que sin importar la cantidad de registros use siempre el > indice? > y para que querrías hacer eso? la idea es optimizar, no desoptimizar. Y no, usar un índice no siempre es la mejor idea. como te comento Rodrigo, deberias mostrarnos cuantos registros hay por cada estado para poder saber si lo que está pasando es lógico o no. además, podrías ejecutar un EXPLAIN ANALYZE de la consulta con INACTIVO, con ACTIVO y ejecutar SET enable_seqscan TO OFF; y luego otra vez el EXPLAIN ANALYZE con ACTIVO. eso debería dar suficiente información para emitir un criterio informado. -- 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 ([email protected]) Para cambiar tu suscripción: http://www.postgresql.org/mailpref/pgsql-es-ayuda
