From: Manfred Koizar <mkoi-pg@aon.at>
To: Fernando Papa <fpapa@claxson.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: I can't wait too much: Total runtime 432478.44 msec
Date: Mon, 04 Aug 2003 16:10:18 +0200
Message-ID: <i2psivsr6r78efetf3fcb3h5h6k9ruc8fc@4ax.com> (raw)
In-Reply-To: <F1DC5B511E2D1C499E5E20FC6D74160D03A04E56@exch2000.buehuergo.corp.claxson.com>
References: <F1DC5B511E2D1C499E5E20FC6D74160D03A04E56@exch2000.buehuergo.corp.claxson.com>
On Fri, 1 Aug 2003 18:17:17 -0300, "Fernando Papa" <fpapa@claxson.com>
wrote:
> AND cont_publicacion.fecha_publicacion = (SELECT
>max(cp1.fecha_publicacion)
> FROM cont_publicacion cp1
> WHERE cp1.id_instalacion =
>cont_publicacion.id_instalacion
> AND cp1.id_contenido = cont_publicacion.id_contenido
>
> AND cp1.generar_vainilla =
>cont_publicacion.generar_vainilla)
If certain uniqueness conditions are met, the Postgres specific
DISTINCT ON clause could help totally eliminating the subselect:
SELECT DISTINCT ON (
cp.id_instalacion,
cp.id_contenido,
cp.generar_vainilla,
cp.fecha_publicacion
)
cc.id_contenido
,cc.pertenece_premium
,cc.Titulo_esp as v_sufix
,cc.url_contenido
,cc.tipo_acceso
,cc.id_sbc
,cc.cant_vistos
,cc.cant_votos
,cc.puntaje_total
,cc.id_contenido_padre
,jc.imagen_tapa_especial
,jc.info_general_esp as info_general
,jc.ayuda
,jc.tips_tricks_esp as tips_tricks
,jc.mod_imagen_tapa_especial
,cp.fecha_publicacion as fecha_publicacion
,cp.generar_Vainilla
FROM
cont_contenido cc
,juegos_config jc
,cont_publicacion cp
WHERE
cc.id_instalacion = 2
AND cc.id_sbc = 619
AND cc.id_tipo = 2
AND cc.id_instalacion = jc.id_instalacion
AND cc.id_contenido = jc.id_contenido
AND upper(cp.generar_Vainilla) = 'S'
AND cp.id_instalacion = cc.id_instalacion
AND cp.id_contenido = cc.id_contenido
ORDER BY
cp.id_instalacion,
cp.id_contenido,
cp.generar_vainilla,
cp.fecha_publicacion desc
However, this doesn't get the result in the original order, so you
have to wrap another SELECT ... ORDER BY ... LIMIT around it. Or try
to move the subselect into the FROM clause:
SELECT
cc.id_contenido
,cc.pertenece_premium
,cc.Titulo_esp as v_sufix
,cc.url_contenido
,cc.tipo_acceso
,cc.id_sbc
,cc.cant_vistos
,cc.cant_votos
,cc.puntaje_total
,cc.id_contenido_padre
,jc.imagen_tapa_especial
,jc.info_general_esp as info_general
,jc.ayuda
,jc.tips_tricks_esp as tips_tricks
,jc.mod_imagen_tapa_especial
,cp.fecha_publicacion as fecha_publicacion
,cp.generar_Vainilla
FROM
cont_contenido cc
,juegos_config jc
,(SELECT DISTINCT ON (
id_instalacion,
id_contenido,
generar_vainilla,
fecha_publicacion
)
*
FROM cont_publicacion
ORDER BY
id_instalacion,
id_contenido,
generar_vainilla,
fecha_publicacion desc
) AS cp
WHERE
cc.id_instalacion = 2
AND cc.id_sbc = 619
AND cc.id_tipo = 2
AND cc.id_instalacion = jc.id_instalacion
AND cc.id_contenido = jc.id_contenido
AND upper(cp.generar_Vainilla) = 'S'
AND cp.id_instalacion = cc.id_instalacion
AND cp.id_contenido = cc.id_contenido
ORDER BY
cp.fecha_publicacion desc
LIMIT 10
OFFSET 0
[completely untested]
Servus
Manfred
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-performance@postgresql.org
Cc: mkoi-pg@aon.at, fpapa@claxson.com
Subject: Re: I can't wait too much: Total runtime 432478.44 msec
In-Reply-To: <i2psivsr6r78efetf3fcb3h5h6k9ruc8fc@4ax.com>
References: <F1DC5B511E2D1C499E5E20FC6D74160D03A04E56@exch2000.buehuergo.corp.claxson.com> <i2psivsr6r78efetf3fcb3h5h6k9ruc8fc@4ax.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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