Cách tốt nhất để đếm tổng số hàng trong một bảng: COUNT(*) so với COUNT(1)

Tác giả: Denis Magda
Ngày xuất bản: 2023-11-01T00:00:00
Length: 15:20

If you need to count the total number of rows in a relational table, the COUNT() function often comes to mind first. However, if you search online, you'll come across many resources suggesting that COUNT(1) is more efficient. So, should we use COUNT(), COUNT(1), or even COUNT(id)?

In this video, you'll learn which version of the COUNT function is the most efficient by reviewing how the function works, comparing execution plans, and analyzing latencies across four major databases: PostgreSQL, Oracle, MySQL, and SQL Server.

0:00 COUNT(*) vs. COUNT(1) dilemma

0:40 PostgreSQL, comparing execution plans

4:30 PostgreSQL, comparing latencies

5:32 Oracle, comparing execution plans

7:30 Oracle, comparing latencies

8:25 MySQL, comparing execution plans

9:20 MySQL, comparing latencies

10:50 SQL Server, comparing execution plans

12:52 SQL Server, comparing latencies

13:17 When does an index make things faster?

Curios to learn even more about databases, follow me here:

* Medium: https://medium.com/@magda7817

* X (Twitter): https://twitter.com/denismagda

Dịch Vào Lúc: 2025-06-29T14:40:38Z

Yêu cầu dịch (Một bản dịch khoảng 5 phút)

Phiên bản 3 (ổn định)

Tối ưu hóa cho một người nói. Phù hợp cho video chia sẻ kiến thức hoặc giảng dạy.

Video Đề Xuất