Remove unnecessary "lmgr.h" in stat_utils.c

Started by Ilia Evdokimovover 1 year ago6 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

appliesbuild failedCI history

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t51536_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t51536_1 && git checkout t51536_1

Patchset v1 (message #1) is on t51536_1

Jump to latest
#1Ilia Evdokimov
ilya.evdokimov@tantorlabs.com

Hi hackers,

While reviewing the import/export statistics, I noticed that relation
locking are handled via relation_open() and relation_close() in
stats_lock_check_privileges(), and no calls to other lock-manager
routines are actually used there. As a result, the inclusion of the
lock-manager header

#include "storage/lmgr.h"

is not needed. I have attached a small patch which simply removes that
include.

--
Best regards,
Ilia Evdokimov,
Tantor Labs LLC.

Attachments:

t51536_1
v1-0001-Remove-unused-lmgr.h-from-statistics-utilities.patchtext/x-patch; charset=UTF-8; name=v1-0001-Remove-unused-lmgr.h-from-statistics-utilities.patchDownload+0-2
#2Michael Paquier
michael@paquier.xyz
In reply to: Ilia Evdokimov (#1)
Re: Remove unnecessary "lmgr.h" in stat_utils.c

On Mon, May 05, 2025 at 04:33:20PM +0300, Ilia Evdokimov wrote:

While reviewing the import/export statistics, I noticed that relation
locking are handled via relation_open() and relation_close() in
stats_lock_check_privileges(), and no calls to other lock-manager routines
are actually used there. As a result, the inclusion of the lock-manager
header

#include "storage/lmgr.h"

is not needed. I have attached a small patch which simply removes that
include.

True that we try to be clean when it comes to that.

I suspect that this is an artifact from one of the original versions
of the patch compared to what has been committed when this feature has
been discussed. Corey?
--
Michael

#3Bertrand Drouvot
bertranddrouvot.pg@gmail.com
In reply to: Michael Paquier (#2)
Re: Remove unnecessary "lmgr.h" in stat_utils.c

Hi,

On Wed, May 07, 2025 at 09:10:17AM +0900, Michael Paquier wrote:

On Mon, May 05, 2025 at 04:33:20PM +0300, Ilia Evdokimov wrote:

While reviewing the import/export statistics, I noticed that relation
locking are handled via relation_open() and relation_close() in
stats_lock_check_privileges(), and no calls to other lock-manager routines
are actually used there. As a result, the inclusion of the lock-manager
header

#include "storage/lmgr.h"

is not needed. I have attached a small patch which simply removes that
include.

True that we try to be clean when it comes to that.

Re-sharing my thoughts as it looks like that my previous email did not reach the
mailing list (yet?): probably because the attachement mentioned below was too
large.

"
Thanks for the report!

Indeed, and that's what clang-tidy (misc-include-cleaner) also reports:

$ run-clang-tidy -checks="-*,misc-include-cleaner" | grep "is not used directly" | grep stat_utils.c
../src/backend/statistics/stat_utils.c:26:1: warning: included header lmgr.h is not used directly [misc-include-cleaner]

Actually it reports much more (see attached):

$ run-clang-tidy -checks="-*,misc-include-cleaner" | grep -c "is not used directly"
794

I did not look to check if all of them make sense (I'd guess probably not), but
I'm wondering if it would make sense to work an a "larger" cleanup instead?
(in the same vein as [1]/messages/by-id/af837490-6b2f-46df-ba05-37ea6a6653fc@eisentraut.org did)

[1]: /messages/by-id/af837490-6b2f-46df-ba05-37ea6a6653fc@eisentraut.org

"

Regards,

--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

#4Bertrand Drouvot
bertranddrouvot.pg@gmail.com
In reply to: Bertrand Drouvot (#3)
Re: Remove unnecessary "lmgr.h" in stat_utils.c

Hi,

On Wed, May 07, 2025 at 07:28:01AM +0000, Bertrand Drouvot wrote:

Hi,

On Wed, May 07, 2025 at 09:10:17AM +0900, Michael Paquier wrote:

On Mon, May 05, 2025 at 04:33:20PM +0300, Ilia Evdokimov wrote:

While reviewing the import/export statistics, I noticed that relation
locking are handled via relation_open() and relation_close() in
stats_lock_check_privileges(), and no calls to other lock-manager routines
are actually used there. As a result, the inclusion of the lock-manager
header

#include "storage/lmgr.h"

is not needed. I have attached a small patch which simply removes that
include.

True that we try to be clean when it comes to that.

Re-sharing my thoughts as it looks like that my previous email did not reach the
mailing list (yet?): probably because the attachement mentioned below was too
large.

"
Thanks for the report!

Indeed, and that's what clang-tidy (misc-include-cleaner) also reports:

$ run-clang-tidy -checks="-*,misc-include-cleaner" | grep "is not used directly" | grep stat_utils.c
../src/backend/statistics/stat_utils.c:26:1: warning: included header lmgr.h is not used directly [misc-include-cleaner]

Actually it reports much more (see attached):

$ run-clang-tidy -checks="-*,misc-include-cleaner" | grep -c "is not used directly"
794

I did not look to check if all of them make sense (I'd guess probably not), but
I'm wondering if it would make sense to work an a "larger" cleanup instead?
(in the same vein as [1] did)

[1]: /messages/by-id/af837490-6b2f-46df-ba05-37ea6a6653fc@eisentraut.org

"

FWIW, please find attached a subset of the initial report that focus on
the "is not used directly" warnings.

Regards,

--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Attachments:

report_is_not_used_directly.txttext/plain; charset=us-asciiDownload
#5Michael Paquier
michael@paquier.xyz
In reply to: Bertrand Drouvot (#4)
Re: Remove unnecessary "lmgr.h" in stat_utils.c

On Wed, May 07, 2025 at 05:56:55PM +0000, Bertrand Drouvot wrote:

FWIW, please find attached a subset of the initial report that focus on
the "is not used directly" warnings.

Seems worth doing to simplify the code in the long-run, even if these
require a case-by-case manual lookup. Did you cross-check with the
information that IWYU generates? Do we have some consistency?

All that is potential work for v19, of course.
--
Michael

#6Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Michael Paquier (#5)
Re: Remove unnecessary "lmgr.h" in stat_utils.c

On 2025-May-08, Michael Paquier wrote:

Seems worth doing to simplify the code in the long-run, even if these
require a case-by-case manual lookup.

Yeah, I don't think we can take a patch that simply removes everything
that this report mentions, because some of the includes (especially the
system includes) could be platform-dependent. Also I imagine some of
them depend on compile-time environment -- e.g., I'm pretty sure
src/port/pg_popcount_aarch64.c is not going to work well without
pg_bitutils.h.

All that is potential work for v19, of course.

Yep.

--
Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/
"Update: super-fast reaction on the Postgres bugs mailing list. The report
was acknowledged [...], and a fix is under discussion.
The wonders of open-source !"
https://twitter.com/gunnarmorling/status/1596080409259003906