SQL Server; index on TEXT column

后端 未结 5 1488
轻奢々
轻奢々 2021-01-02 15:34

I have a database table with several columns; most of them are VARCHAR(x) type columns, and some of these columns have an index on them so that I can search qui

相关标签:
5条回答
  • 2021-01-02 16:15

    Searching TEXT fields is always pretty slow. Give Full Text Search a try and see if that works better for you.

    0 讨论(0)
  • 2021-01-02 16:23

    If your queries are like LIKE '%string%' (i. e. you search for a string inside a TEXT field), then you'll need a FULLTEXT index.

    If you search for a substring in the beginning of the field (LIKE 'string%') and use SQL Server 2005 or higher, then you can convert your TEXT into a VARCHAR(MAX), create a computed column and index this column.

    See this article in my blog for performance details:

    • Indexing VARCHAR(MAX)
    0 讨论(0)
  • 2021-01-02 16:23

    You can do complex boolean querying in FTS; like

    contains(yourcol,'"My first sting" or "my second string" and "my third string"')

    Depending on your query ContainsTable or freetexttable might give better results.

    If you are connecting through .Net you might want to look at A google full text search

    0 讨论(0)
  • 2021-01-02 16:34

    And since nobody has already said it (maybe because it's obvious) querying LIKE '%string%' bypasses your existing indexes - so it'll run slow. Hence - why you need to use full text indexing. (which is what Quassnoi said).

    Correction - I'm sure I learnt this, and always believed it - but after some investigating it (using wildcard at the start) seems OK? My old regex queries run better with likes!

    0 讨论(0)
  • 2021-01-02 16:39

    You should be looking at using Full Text Indexing on the column.

    0 讨论(0)
提交回复
热议问题