Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
562 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 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...