相关疑难解决方法(0)

PostgreSQL LIKE查询性能变化

关于LIKE查询数据库中特定表的响应时间,我看到了相当大的变化.有时我会在200-400毫秒内得到结果(非常可接受),但有时候返回结果可能需要30秒.

我知道LIKE查询是非常耗费资源的,但我只是不明白为什么响应时间会有这么大的差异.我已经在该owner1字段上构建了一个btree索引,但我认为这对LIKE查询没有帮助.有人有主意吗?

示例SQL:

SELECT gid, owner1 FORM parcels
WHERE owner1 ILIKE '%someones name%' LIMIT 10
Run Code Online (Sandbox Code Playgroud)

我也尝试过:

SELECT gid, owner1 FROM parcels
WHERE lower(owner1) LIKE lower('%someones name%') LIMIT 10
Run Code Online (Sandbox Code Playgroud)

和:

SELECT gid, owner1 FROM parcels
WHERE lower(owner1) LIKE lower('someones name%') LIMIT 10
Run Code Online (Sandbox Code Playgroud)

有类似的结果.
表行数:约95,000.

postgresql indexing query-optimization pattern-matching sql-like

103
推荐指数
3
解决办法
7万
查看次数

安全的ActiveRecord就像查询一样

我正在尝试编写LIKE查询.

我读到纯字符串quires不安全,但我找不到任何解释如何编写安全的LIKE Hash Query的文档.

可能吗?我应该手动防御SQL注入吗?

ruby activerecord ruby-on-rails-4

73
推荐指数
3
解决办法
5万
查看次数

ActiveRecord :: StatementInvalid SQLite3 :: SQLException:没有这样的列:true:

我希望@messages返回@folder.messages,其中"已删除"列的值不等于true.我不确定为什么这会继续抛出SQLException.我想我没有正确格式化已删除的属性,但我不确定如何解决它.

任何帮助将不胜感激.提前致谢.

错误信息:

ActiveRecord::StatementInvalid in MailboxController#index  
SQLite3::SQLException: no such column: true: SELECT     "message_copies".* FROM       "message_copies"  WHERE     ("message_copies".folder_id = 1) AND (deleted != true)  
Run Code Online (Sandbox Code Playgroud)

应用跟踪:

app/controllers/mailbox_controller.rb:14:in `show'  
app/controllers/mailbox_controller.rb:5:in `index'  
Run Code Online (Sandbox Code Playgroud)

Mailbox_Controller.rb

1   class MailboxController < ApplicationController  
2     def index  
3       current_user = User.find(session[:user_id])  
4       @folder = Folder.where("user_id = #{current_user.id}").first  
5       show  
6       render :action => "show"  
7     end
8  
9     def show  
10      current_user = User.find(session[:user_id])  
11      @folder = Folder.where("user_id = #{current_user.id}").first  
12      @msgs = @folder.messages  
13      @ms = @msgs.where("deleted != true") …
Run Code Online (Sandbox Code Playgroud)

sqlite ruby-on-rails sqlexception sqlite3-ruby ruby-on-rails-3

7
推荐指数
1
解决办法
7221
查看次数