如何快速搜索查询

发布于 2024-10-18 12:09:02 字数 524 浏览 4 评论 0原文

我有一个应用程序,其中几乎所有内容都是动态的。我正在为用户创建一个编辑表单,本质上需要搜索查询以选择一组复选框。

我有一个表,将用户分配给保存 userid 和 programid 的程序,这些程序映射到用户表和程序表中的相应记录。最初,我获取一个用户和所有程序,然后循环程序查询以构建复选框。

<cfloop query="Rc.programs">
    <dd><input type="checkbox" name="programs" value="#Rc.programs.id#" /> #Rc.programs.name#</dd>
</cfloop>

我理想的做法是提取计划成员资格表中的所有记录,并对其进行某种搜索。我可以执行查询的查询,但我想知道是否有更快的方法来本质上搜索查询。如果这有助于人们理解,我的查询将如下所示。

从 Rc.programs 中选择*,其中programid = #Rc.programs.id#

I have an application where almost everything is dynamic. I am creating an edit form for a user and essentially need to search a query to select a group of checkboxes.

I have a table assigning the user to programs that holds userid and programid which maps to the corresponding records in the users table and the programs table. Initially I grab one user and all the programs and I loop over the programs query to build the checkboxes.

<cfloop query="Rc.programs">
    <dd><input type="checkbox" name="programs" value="#Rc.programs.id#" /> #Rc.programs.name#</dd>
</cfloop>

What I ideally want to do is pull all records in the program memberships table and do some sort of search through that. I could do a query of queries, but I was wondering if there was a faster way to essentially search a query. My query of queries would be like the following if this helps people understand.

SELECT * FROM Rc.programs WHERE programid = #Rc.programs.id#

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软甜啾 2024-10-25 12:09:02

QoQ 当然是最简单的方法,但不要忘记 CFQUERYPARAM:

SELECT * FROM Rc.programs WHERE programid =
   <cfqueryparam value="#Rc.programs.id#" cfsqltype="WHATEVER_IT_IS">

您还可以将查询的单个列/字段引用为数组,并使用数组函数(包括 arrayFind())仅搜索该列(其中可能只是最近的版本)。

arrayFind( Rc.programs.programId, YOUR_ID_HERE )

如果这还不够快,您总是可以在内存中构建某种数据结构或索引,并将其保存在应用程序范围变量中(如果合适)。

但你的数据库真的那么慢吗?减少页面执行的查询数量几乎总是一件好事,但对于一般的、简单的查询,您可能无法击败数据库服务器的速度、缓存等。

QoQ is certainly the easiest way to do it, but don't forget your CFQUERYPARAM:

SELECT * FROM Rc.programs WHERE programid =
   <cfqueryparam value="#Rc.programs.id#" cfsqltype="WHATEVER_IT_IS">

You can also reference an individual column/field of a query as an array, and search through just that column using array functions, including arrayFind() (which might just be in recent versions).

arrayFind( Rc.programs.programId, YOUR_ID_HERE )

If that's not fast enough you could always build some sort of data structure or index in memory, and keep it around in an Application-scope variable if such is appropriate.

But is your database really that slow? Reducing the number of queries executed by a page is almost always a good thing, but for average, uncomplicated queries you probably won't be able to beat the speed, caching, etc of your DB server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文