Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
559 views
in Technique[技术] by (71.8m points)

sql - I need to implement wildcard search using % on both ends, how can I improve performance?

I will be implementing this in the sql side, so I would end up having something like

where company.name like '%:parameter%'

I've read before that this would then make it impossible for the DB to use the company.name index.

My question then would be, what other options do I have to minimize the performance degradation that this will introduce to the search? Please note that, this is client requirements therefore I don't have the option to not implement (even though I explained to them the performance consequence of this).

The application is using Sybase SE 12.5.3 (based on the driver used in DBArtisan 8.5.5)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I don't know Sybase, but you could do something along the lines below:

  • Create a second field, which is the reverse of the company name.
  • Add an index on this new field
  • Use the following where clause

    WHERE company_name like ':parameter%' or reverse_name like Reverse(parameter)+'%'

Hope this points you in a good direction


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...