Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I have this table:

CREATE TABLE IF NOT EXISTS `usergroups` (
      `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
      `user_id` int(11) unsigned NOT NULL,
      `group_id` smallint(5) unsigned NOT NULL,
      PRIMARY KEY (`group_id`,`user_id`),
      KEY `id` (`id`),
      KEY `user_id` (`user_id`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=5496 ;

when run this query:

EXPLAIN SELECT `UserGroup`.`user_id` FROM   `usergroups` AS `UserGroup` WHERE  `UserGroup`.`group_id` = 1 limit 30

its out put is:

1       SIMPLE        UserGroup      ref  PRIMARY  PRIMARY  2        const  543      Using index

I think something is wrong! because it affected 543 rows but I think it should affect 30 rows at maximum. Is it true?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Limit does have an impact on how many rows are selected/affected. 543 is just the number of rows which match the joins and the where clause.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.