Discussions
Categories
- 196.8K All Categories
- 2.2K Data
- 239 Big Data Appliance
- 1.9K Data Science
- 450.3K Databases
- 221.7K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 550 MySQL Community Space
- 478 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3K ORDS, SODA & JSON in the Database
- 544 SQLcl
- 4K SQL Developer Data Modeler
- 187K SQL & PL/SQL
- 21.3K SQL Developer
- 295.8K Development
- 17 Developer Projects
- 138 Programming Languages
- 292.5K Development Tools
- 107 DevOps
- 3.1K QA/Testing
- 646K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 155 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.1K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 18 Java Essentials
- 160 Java 8 Questions
- 86K Java Programming
- 80 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 204 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 439 LiveLabs
- 38 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 171 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 232 Portuguese
Oracle Berkeley DB "heap" access method misscounts records in "db.stat()"

I am working in supporting HEAP access method in "berkeleydb" bindings for Python and I have found a bug affecting BDB 6.2 and 18.1. BDB 5.3 works fine.
Steps to reproduce:
- Create a HEAP database.
- Add a record.
- Delete that record.
- Do a "stat()" on that database and observe field "nrecs" (number of record in the database).
If you use "DB_FAST_STAT", a Zero is returned. That value is correct. If if you request a full database scan, ONE is returned. That value is incorrect. Moreover, that faulty result will be stored in the cache, so future "stat" with "DB_FAST_STAT" will be wrong.
Scanning the database with a cursor will show that the database is empty, as it should.
For some reason, a "stat" scanning a HEAP database will wrongly count deleted records.
The test sourcecode is: (Python using an unreleased version of "berkeleydb" bindings)
"""
self.env = db.DBEnv()
self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL |
db.DB_INIT_LOG | db.DB_INIT_TXN)
self.db = db.DB(self.env)
self.db.open(flags=db.DB_CREATE, dbtype=db.DB_HEAP)
key = self.db.append(data=b'value')
self.db.delete(key)
print(self.db.stat(db.DB_FAST_STAT))
print(self.db.stat())
print(self.db.stat(db.DB_FAST_STAT))
"""
The values printed in my environment are: (notice the wrong number in "nrecs"):
"""
{'magic': 476546, 'metaflags': 0, 'ext_files': 0, 'nrecs': 0, 'pagecnt': 3, 'pagesize': 8192, 'nregions': 1, 'regionsize': 32664, 'version': 2}
{'magic': 476546, 'metaflags': 0, 'ext_files': 0, 'nrecs': 1, 'pagecnt': 3, 'pagesize': 8192, 'nregions': 1, 'regionsize': 32664, 'version': 2}
{'magic': 476546, 'metaflags': 0, 'ext_files': 0, 'nrecs': 1, 'pagecnt': 3, 'pagesize': 8192, 'nregions': 1, 'regionsize': 32664, 'version': 2}
"""
Answers
-
More checks. "DB_FAST_STAT" doesn't give a correct count either. Storing a record and doing "db.stat(db.DB_FAST_STAT)" gives a count of zero for 'nrecs' field. BDB 5.3 works fine. BDB 6.2 and 18.1 gives back incorrect stats.