From an efficiency point of view, it'd be much more so to encode your 3000 categories into a
Trie. After that, run your 3 million entries over it. It then becomes a matter of traversing the trie 3 million times rather than making 3,000,000 x 3,000 compares. Sorry I have no code to give.