Subject RE: [firebird-support] Stored Proc vs View, which one has better performance?
Author Leyne, Sean
Sugi,

> I have a table, let say Tbl1, which structure something like this id_cst int,
> id_gd int, qty int.
>
> I want to select from that table, all records that has sum(qty) > 0 group by
> id_cst and id_gd.
>
> I have 2 options to do that :
> 1) create a view with a ddl like this :
> create view tmp (id_cst, id_gd, qty) as
> select id_cst,id_gd,sum(qty) from Tbl1
> group by id_cst,id_gd
>
> then select that view with ddl : select * from tmp where qty > 0
>
> 2) create a stored procedure that returns all records which qty > 0
>
> Between those options, with one has a better performance?

The performance should be almost identical -- not worth worrying about.

There would/could be other reasons for choosing one approach versus the other, but performance for the problem you outlined is not one of them.

Depending on the number entries in Tbl1, I would argue that neither approach would be best. A temporary table where the current total_qty would be maintained would be a better approach, but there are issues about potential transaction deadlocks which you would need to work through, but they are workable.


Sean