Nice right up... however since I'd imagine that in normal use order probably isn't as much an issue, a sort could be run on the words so that you have even less entries in the database... then it is just a matter of sorting the search words as well.
Also if you wanted to be able to return every combination of the words you only have to do one search. This also gives you the ability to search less combinations of subsets of the words if your initial database request returns nothing.
Exactly! Storting (and searching by) the
"sorted substring of words" uses no extra space
and handles all permutations of the
"substring of words" automagically.
Avioding all the space waste of having to store
all of their permutations.