Does index works for LIKE statement in MySQL? - mysql

I have a table (id, title), where id is PK. For a query SELECT * FROM table WHERE title LIKE "%stackoverflow%", I tried indexing title and fulltext indexing title. I used EXPLAIN to check if index works, and both don't work.
I am told index doesn't work for LIKE "%...%". Is this the case?

noup it wont work, however if your index is 'xxx%' it will work,
another thing is your MySQL Version is older than 5.6 your engine HAVE TO BE MyIsam or Aria, but it cannot be Innodb to have a text index

Related

How I can do this in mysql?

I want to make a query that select fields using 'like' but I am not satisfied with the result, for example my register says, "wood table work 45" but if my query is SELECT * FROM schema1.table1 WHERE description LIKE "%table for work%"; returns nothing, I don't want the user need write exactly "table work" or "wood table" to have a result.
Create first a FULL TEXT Index on the column you wants to query this way :
ALTER TABLE `table1`
ADD FULLTEXT INDEX `IndxDescription` (`description`);
You don't need to run an indexer daemon, MySQL does the index / reindex automatically.
FYI: Full-text is supported in InnoDB / MyISAM only in MySQL
reference : http://dev.mysql.com/doc/refman/5.7/en/fulltext-restrictions.html
If you are looking for a more robust solution, consider taking a look on ElasticSearch : https://github.com/elastic/elasticsearch
You might want to look at Natural Language Fulltext search

MATCH in MYSQL 5.5.24 not working

I am writing the following query :
select * from student where match(name,middle name) against('amar');
I am getting error as : The used table type doesn't support FULLTEXT indexes.
I am using mysql version 5.5.24 on wamp server.
How to solve this issue.
Thank you
before Mysql 5.6, full text search is supported by only myisam engine not innodb, it seems you are using innodb engine for this table.
Even it seems that you did not create full text index on table otherwise you will get error at that time also...
full text index is different from btree default index.

Clarification on MySQL 5.6 using IN PLACE alter table for adding/dropping the same index

From the docs:
An ALTER TABLE statement that contains DROP INDEX and ADD INDEX
clauses that both name the same index uses a table copy, not Fast
Index Creation.
This is a bit unclear to me. Is it talking about the NAME of the index? Can someone give an example of a query in which MySQL resorts to a table copy?
Indeed, it sounds like this line is about:
An (One, single) ALTER TABLE statement
that contains (both) a DROP INDEX and an ADD INDEX clause
and both clauses name the same index
and states that such a statement uses a table copy, not Fast Index Creation.
Such a statement would be:
ALTER TABLE MyTable
DROP INDEX MyIndex
ADD INDEX MyIndex(MyColumn);
The documentation is not really clear about the reason behind this, but I think the database want to create an index first and then drop the other index, so the statement by itself can more easily be made atomic. (Creating the index might fail.) If the index name itself is used in the storage as well, that order of first creating then dropping would give a conflict.
After all, fast index creation is a relatively new feature, so they might improve this over time.

How to hint the index to use in a MySQL select query?

I have a MySQL query (running MySQL 5.0.88), which I'm trying to speed up. The underlying table has multiple indices and for the query in question, the wrong index is used (i_active - 16.000 rows, vs. i_iln - 7 rows).
I'm not very experienced with MySQL but read there is a use index hint, which can force mySQL to use a certain index. I'm trying it like this:
SELECT art.firma USE INDEX (i_iln)
...
but this produces a MySQL error.
Question:
Can anyone tell me what I'm doing wrong? (Except running 5.0.88, which I can't change.)
You missed the
FROM table
Correct SQL should be:
SELECT art.firma FROM your_table USE INDEX (i_iln) WHERE ....
select * from table use index (idx);
http://dev.mysql.com/doc/refman/5.0/en/index-hints.html
sometimes, with use index (index_name) optimizer might go for table scan, if you use hint force index, optimizer will be forced to use index, will go for table scan only if no ways left to get the rows with provided index.
SELECT art.firma FROM art FORCE INDEX (i_iln);
for more detail on hints USE INDEX and FORCE INDEX check this link
Select Coloumn1,Coloumn2,Coloumn.... FROM TABLE_NAME USE INDEX(index_name)
WHERE Coloumn="condition";
if you have correct index thn you dnt need to use index(). your query automic select correct index.If your query slow after using index thn recheck your index ,something wrong in index.
thanks in advance.enter code here

Full text search with a very simple MySQL statement

I recently came across a wierd issue with MySQL Fulltext search. My statement is really simple:
SELECT * FROM `mytable` WHERE MATCH (`desc`) AGAINST ('+NOR +710' IN BOOLEAN MODE)
And this is what in the desc column: "The NOR 710 also has smoke seal ..."
For some reason it won't find that row. I added Fulltext index to that column, mysql version is 5.1.56 , database engine of that table is MyISAM. Is there anything else i need to check?
Thanks
By default, fulltext indexes will ignore words that are shorter than 4 charaters. Adjust your ft_min_word_len to also include the shorter words.