That's right. The same number of cells your matrix have. Anyway your data have 100000 records and you will have to write all the combinations in some way.
Using queries your code is simpler and the performance of your application profits from the years of investigation in SQL optimization.