Performance differences between temporary tables and Union all during storage

Source: Internet
Author: User
MACHINE: CPU: 2 GB memory: 2 GB Database: SQL 2005 depends on the machine configuration, the results will be different.
Performance Test Description:
1. query after the database server is restarted. That is, the result of the first query.
2. Compare the database query performance.

Test conditions:
1. Use temporary tables during storage: (proc1) Select Top 1000 *
Into # T1
From somastinsert into # t1select Top 100 * From somast
Select * from # T1
--- Delete table data
Truncate table # T1
-- Delete a temporary table
Drop table # T1 execution time: 1039 Ms

2. Use Union all: (proc2) Select Top 1000 * From somast In the Stored Procedure
Union all
Select Top 100 * From somast execution time is 5017 Ms

Note:
After the preceding two stored procedures are executed once, the preceding two stored procedures are executed again, and the execution time changes substantially.
Stored Procedure proc1, the execution time is 728 Ms
Stored Procedure proc2, with execution time of 998 Ms

However, in practice, although in a short period of time, it is unlikely that the same person will query the same stored procedure twice or more. in most cases, they are executed by different people at different times.
In addition, the optimization of the stored procedure will shorten the execution time after optimization. If optimization can be performed, optimization should be performed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.