java webNovice, recently encountered a requirement is for a table with n fields, the form in the web page also has n input boxes, users can fill in any number of fields of search keywords, and then need to be able to submit any number of keywords combined queries.
Looked for the data that is to use multi-column index to do, but did not find a specific approach, I hope that the boss can from the MySQL database level and code level to explain how this kind of problem should be solved.
Determine whether all fields have values, and dynamically splice the SQL statements for processing.
It’s nothing to do with the index. The index just speeds up the query. You should get GET or POST values on the Java side, then do SQL splicing, and then execute them.
Generally speaking, you can try to analyze whether query conditions have parent-child relationship to establish an index including multiple indexes. Once the index is possible to query independently, it is not the first field that can not appear in the joint index.
According to the data from the foreground, to extract all the attribute names and attribute values, and then determine whether the attribute values have value, if there is a value, according to the attribute name to stitch the corresponding SQL statement query conditions, and ultimately execute the entire SQL