According to this Bitcoin stores the user's keys and some additional data in a file called wallet.dat, which is a Berkley DB. Let's suppose the wallet.dat contained only the user's keys. Let's also suppose we're using linux.
What is then the main reason for Bitcoin to store keys in a database? Wouldn't it have the same effect if keys were stored as flat files: the public key would be the filename and the private key would be the content of the file?
Even if we had millions of keys, and therefore millions of files in a single directory, the i-node limit (maximum number of files in a directory) and file lookup speed shouldn't be a problem. The majority of linux systems use the ext4 as its filesystem and according to this the number of i-nodes in ext4 is unlimited (limited only by the disk memory). Also according to this the EXT4 uses a structure called HTree, which allows for file lookups to have a constant time complexity.