mirror of
https://github.com/postgres/postgres.git
synced 2025-12-21 05:21:08 +03:00
Avoid using list_length() to test for empty list.
The standard way to check for list emptiness is to compare the List pointer to NIL; our list code goes out of its way to ensure that that is the only representation of an empty list. (An acceptable alternative is a plain boolean test for non-null pointer, but explicit mention of NIL is usually preferable.) Various places didn't get that memo and expressed the condition with list_length(), which might not be so bad except that there were such a variety of ways to check it exactly: equal to zero, less than or equal to zero, less than one, yadda yadda. In the name of code readability, let's standardize all those spellings as "list == NIL" or "list != NIL". (There's probably some microscopic efficiency gain too, though few of these look to be at all performance-critical.) A very small number of cases were left as-is because they seemed more consistent with other adjacent list_length tests that way. Peter Smith, with bikeshedding from a number of us Discussion: https://postgr.es/m/CAHut+PtQYe+ENX5KrONMfugf0q6NHg4hR5dAhqEXEc2eefFeig@mail.gmail.com
This commit is contained in:
@@ -339,7 +339,7 @@ CreateStatistics(CreateStatsStmt *stmt)
|
||||
if ((list_length(stmt->exprs) == 1) && (list_length(stxexprs) == 1))
|
||||
{
|
||||
/* statistics kinds not specified */
|
||||
if (list_length(stmt->stat_types) > 0)
|
||||
if (stmt->stat_types != NIL)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("when building statistics on a single expression, statistics kinds may not be specified")));
|
||||
@@ -391,7 +391,7 @@ CreateStatistics(CreateStatsStmt *stmt)
|
||||
* automatically. This allows calculating good estimates for stats that
|
||||
* consider per-clause estimates (e.g. functional dependencies).
|
||||
*/
|
||||
build_expressions = (list_length(stxexprs) > 0);
|
||||
build_expressions = (stxexprs != NIL);
|
||||
|
||||
/*
|
||||
* Check that at least two columns were specified in the statement, or
|
||||
|
||||
Reference in New Issue
Block a user