Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Code runs in 53s but in SP runs forever
Message
De
25/02/2007 20:59:44
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2000
Divers
Thread ID:
01197468
Message ID:
01198706
Vues:
12
I just commented that.
The problem I had was "Parameter sniffing"
A search in Google solved it.
Thanks anyway :)
>I don't see where local variables @dfecha_prom_i and @dfecha_prom_f came from.
>Also it's not a good idea to use meaningless one letter table aliases. They make queries unreadable and hard to maintain.
>
>>I have the most strange situation.
>>I have this code in a Stored procedure:
>>
>>
>>CREATE PROCEDURE crea_ventas_cliente
>>@cid_plan char(10),
>>@error_msg char(100) output
>>
>>AS
>>
>>/*declares here  */
>>insert into monithor..ventas_cliente( cid_plan, cid_clie, carticulos_id, ccategoria_3, cproveedor_id, nimporte, npeso)
>>	select @cid_plan, a.cid_clie, b.carticulos_id, c.ccategoria_3, c.cproveedor_id,
>>	sum(round(b.nimporte_total,2) * (1 - b.lgratuito) * case when a.ctipo_documento_id = 'NC' then -1 else 1 end )
>>	as nimporte,
>>	sum(b.npeso_detalle * case when a.ctipo_documento_id = 'NC' then -1 else 1 end )
>>	as npeso
>>	from
>>	ventas.._movimiento_ventas a,
>>	ventas.._movimiento_ventas_detalle b,
>>	bdmain.._articulos c
>>	where
>>	a.dfecha_documento >= @dfecha_prom_i  and
>>	a.dfecha_documento <= @dfecha_prom_f  and
>>	a.cnumero_documento  = b.cnumero_documento  and
>>	b.carticulos_id       = c.carticulos_id     and
>>	a.ctipo_documento_id = b.ctipo_documento_id and
>>	a.cserie_documento   = b.cserie_documento   and
>>	a.cestado_documento_id <> 'X' and
>>	a.ctipo_documento_id in ('FA', 'BO', 'NC', 'ND') and
>>	b.ckits              <> '1'
>>	group by
>>	a.cid_clie, b.carticulos_id,
>>	c.ccategoria_3, c.cproveedor_id
>>
>>If I call this stored procedure:
>>
>>declare @error2 char(100)
>>exec monithor..crea_ventas_cliente '0000000012',@error2
>>
>>
>>it takes hours to run (at least 5 hours. I stopped execution)
>>
>>
>>But if I run the code directly in the query analyser it only takes 53 seconds to run the insert command. I traced the stored procedure and the delay is in the insert command, but this very same command run directly executes very quick.
>>I already trieb both approach after booting the computer and made sure that the SP code is exactly the same as the direct code.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform