Bug #43084 COUNT can often be shortcut
Submitted: 21 Feb 2009 21:55 Modified: 3 Apr 2009 11:45
Reporter: Jeff Veit Email Updates:
Status: Verified Impact on me:
Category:MySQL Server: General Severity:S4 (Feature request)
Version: OS:Any
Assigned to: CPU Architecture:Any
Tags: count

[21 Feb 2009 21:55] Jeff Veit
When programming, in my experience count is used for two reasons:
1. To find an accurate count of rows.
2. To make a decision.

In case 2, what I as a programmer most often needs to know is are there 0, 1 or more rows.

For these cases, I suspect that there are optimizations that could be applied if the engine knew that a full count was not required.

How to repeat:
Feature suggestion

Suggested fix:
I suggest a variation on COUNT syntax that includes the information that a full count is not needed.

Perhaps COUNT ... WHERE DECISION or COUNT WHERE BRANCH or COUNT WHERE IF. ALternatively perhaps COUNTIF would be better. A more general version could allow the programmer to decide the break points. For instance, if there's a small amount of data (e.g. 30 rows) then I often find myself displaying it one way, but if there are more then I display it in a more concise form. Perhaps COUNTIF (0, break1, .... breakn), returning an integer 0 for the first, 1 for <= break1, etc.
[3 Apr 2009 11:45] Susanne Ebrecht
Many thanks for writing a feature request. We will discuss this.