MySQL Forums
Forum List  »  Optimizer & Parser

Re: Index evaluation
Posted by: Drei Bit
Date: July 24, 2007 04:33AM

Hello

KimSeong Loh Wrote:
-------------------------------------------------------
> Your txt column is a TEXT type, you only index the
> first 250 characters.
> Even though it could work but probably the
> optimiser is not smart enough to detect that.
> Maybe submit a feature request.

That makes Sense! Bu unfortunately changing the whole thing to varchar does not change the situation!

CREATE TABLE t2(
    lid INT NOT NULL AUTO_INCREMENT, 
    id INT NOT NULL, 
    txt VARCHAR(500),

    CONSTRAINT pk_t2 PRIMARY KEY (lid),

    INDEX ix_id (id),
    INDEX ix_txt USING BTREE(txt),
    INDEX ix_txt_id USING BTREE(txt,id)

) ENGINE=InnoDB;

explain
select * from t1 join ( select id from t2 use index (ix_txt_id)	where txt like 'Hall%' ) as y on y.id = t1.id;
/*
+----+-------------+------------+--------+---------------+-----------+---------+------+------+-------------+
| id | select_type | table      | type   | possible_keys | key       | key_len | ref  | rows | Extra       |
+----+-------------+------------+--------+---------------+-----------+---------+------+------+-------------+
|  1 | PRIMARY     | <derived2> | ALL    | NULL          | NULL      | NULL    | NULL |   80 |             |
|  1 | PRIMARY     | t1         | eq_ref | PRIMARY       | PRIMARY   | 4       | y.id |    1 |             |
|  2 | DERIVED     | t2         | range  | ix_txt_id     | ix_txt_id | 768     | NULL |   80 | Using where |
+----+-------------+------------+--------+---------------+-----------+---------+------+------+-------------+
*/

explain select id from t2 use index (ix_txt_id) where txt like 'Hall%';
/*
+----+-------------+-------+-------+---------------+-----------+---------+------+------+-------------+
| id | select_type | table | type  | possible_keys | key       | key_len | ref  | rows | Extra       |
+----+-------------+-------+-------+---------------+-----------+---------+------+------+-------------+
|  1 | SIMPLE      | t2    | range | ix_txt_id     | ix_txt_id | 768     | NULL |   80 | Using where |
+----+-------------+-------+-------+---------------+-----------+---------+------+------+-------------+

*/

Greetings
3bit

PS. is there any code-highlighting feature in this Forum? (Or should I file a Feature Request?)

Options: ReplyQuote


Subject
Views
Written By
Posted
3560
July 23, 2007 04:51PM
2421
July 23, 2007 05:18PM
2366
July 24, 2007 02:06AM
Re: Index evaluation
2377
July 24, 2007 04:33AM
2396
July 23, 2007 07:27PM
2334
July 24, 2007 05:24AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.