1. A method for collecting and storing string match and substring match statistics for a database of documents composed in a language of strings associated with attributes, comprising: providing a memory limit value; providing a database including a plurality of data content values, wherein said data content values comprise strings and substrings; constructing a histogram consisting of multiple buckets of partitioned path-value pairs using a data model to construct a value synopsis for each of said buckets, wherein each bucket stores an average selectivity for the path-value pairs belonging to the bucket, wherein the constructing is such that the value synopsis encodes both a probability that a full string belongs to a given bucket, and an estimate of a frequency of sub-strings in each bucket, and summarization of data model parameters so that entire histogram fits within said memory limit value, and returning estimated selectivity i) for the full string as the average selectivity of an appropriate bucket and ii) for the sub-string as a weighted sum across all buckets of the average selectivity times the frequency of sub-strings in each bucket.