From cf4d9d98f25b0fe684bf183d873fa7f9a6efc56b Mon Sep 17 00:00:00 2001 From: Danuul3 <134265589+Danuul3@users.noreply.github.com> Date: Wed, 29 Nov 2023 16:49:54 +0300 Subject: [PATCH] The ability to retrieve the total number of pages in the database, the (#7888) number of pages in use, and the number of free pages via the GET_CONTEXT. Co-authored-by: Daniil --- doc/sql.extensions/README.context_variables2 | 6 ++++++ src/jrd/SysFunction.cpp | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/doc/sql.extensions/README.context_variables2 b/doc/sql.extensions/README.context_variables2 index 9d5b8ddb2b..da589760c8 100644 --- a/doc/sql.extensions/README.context_variables2 +++ b/doc/sql.extensions/README.context_variables2 @@ -142,6 +142,12 @@ Usage: | DECFLOAT_TRAPS | Exceptional conditions in operations with DECFLOAT | values that cause a trap. + | + PAGES_ALLOCATED | Current value of allocated pages in the database. + | + PAGES_USED | Current value of allocated pages in the database. + | + PAGES_FREE | Current value of free pages in the database. Notes: To prevent DoS attacks against Firebird Server you are not allowed to have diff --git a/src/jrd/SysFunction.cpp b/src/jrd/SysFunction.cpp index cafa2bd72e..6df7ab307e 100644 --- a/src/jrd/SysFunction.cpp +++ b/src/jrd/SysFunction.cpp @@ -432,6 +432,12 @@ static const char FALSE_VALUE[] = "FALSE", TRUE_VALUE[] = "TRUE"; +// Get pages +const char + PAGES_ALLOCATED[] = "PAGES_ALLOCATED", + PAGES_USED[] = "PAGES_USED", + PAGES_FREE[] = "PAGES_FREE"; + double fbcot(double value) noexcept { @@ -4583,6 +4589,18 @@ dsc* evlGetContext(thread_db* tdbb, const SysFunction*, const NestValueArray& ar GuidToString(guidBuffer, &dbb->dbb_guid); resultStr = string(guidBuffer); } + else if (nameStr == PAGES_ALLOCATED) + { + resultStr.printf("%" ULONGFORMAT, PageSpace::actAlloc(dbb)); + } + else if (nameStr == PAGES_USED) + { + resultStr.printf("%" ULONGFORMAT, PageSpace::usedPages(dbb)); + } + else if (nameStr == PAGES_FREE) + { + resultStr.printf("%" ULONGFORMAT, PageSpace::maxAlloc(dbb) - PageSpace::usedPages(dbb)); + } else if (nameStr == DATABASE_FILE_ID) { resultStr = dbb->getUniqueFileId();