查询表格逻辑:“喜欢”与“等于”

时间:2020-12-14 16:27:03

Our application provides multiple query interfaces that are basically just text inputs. Is there a best practice on whether the backend logic should be pad the query parameter with wildcards then perform a like or should it just do an equals. Of course another option would be to allow user's to use wildcards and then check and use a "like" if appropriate.

我们的应用程序提供多个查询接口,基本上只是文本输入。有关后端逻辑是否应该使用通配符填充查询参数然后执行类似操作或者是否应该执行等于是否有最佳实践。当然,另一种选择是允许用户使用通配符,然后检查并使用“喜欢”(如果适用)。

I understand the performance implication of using a wildcard like this and that this could be viewed as a subject question, I just want to know if there is a standard practice.

我理解使用这样的通配符的性能影响,这可以被视为一个主题问题,我只想知道是否有标准的做法。

1 个解决方案

#1


2  

This is something I would leave up to the user, allowing then to actually make a choice. All the UIs I've seen for allowing user-specified conditions have:

这是我留给用户的东西,然后允许实际做出选择。我见过的允许用户指定条件的所有UI都有:

  • the column to check.
  • 要检查的列。

  • a drop-down box containing the relationship, such as equal to, not equal to, less than, greater than, starts with.
  • 包含关系的下拉框,例如等于,不等于,小于,大于,以...开头。

  • the value you want to compare to.
  • 要比较的值。

Then, for the starts with option, you just tack on % and use like.

然后,对于选项的开始,你只需要在%上使用并使用like。

You'll note (for performance reasons which you seem to already understand) I used starts with rather than like to limit the possibility of dragging down the database performance.

你会注意到(出于你似乎已经理解的性能原因)我使用的是start而不是喜欢限制拖动数据库性能的可能性。

I'm not a big fan of unrestricted like statements although you could also provide ends with for those DBMS' capable of storing reversed indexes.

虽然你也可以为那些能够存储反向索引的DBMS提供最终结果,但我并不是不受限制的类似语句的忠实粉丝。

#1


2  

This is something I would leave up to the user, allowing then to actually make a choice. All the UIs I've seen for allowing user-specified conditions have:

这是我留给用户的东西,然后允许实际做出选择。我见过的允许用户指定条件的所有UI都有:

  • the column to check.
  • 要检查的列。

  • a drop-down box containing the relationship, such as equal to, not equal to, less than, greater than, starts with.
  • 包含关系的下拉框,例如等于,不等于,小于,大于,以...开头。

  • the value you want to compare to.
  • 要比较的值。

Then, for the starts with option, you just tack on % and use like.

然后,对于选项的开始,你只需要在%上使用并使用like。

You'll note (for performance reasons which you seem to already understand) I used starts with rather than like to limit the possibility of dragging down the database performance.

你会注意到(出于你似乎已经理解的性能原因)我使用的是start而不是喜欢限制拖动数据库性能的可能性。

I'm not a big fan of unrestricted like statements although you could also provide ends with for those DBMS' capable of storing reversed indexes.

虽然你也可以为那些能够存储反向索引的DBMS提供最终结果,但我并不是不受限制的类似语句的忠实粉丝。