Jump to content

Impossible WHERE noticed?


fry2010

Recommended Posts

I have several tables, all with a primary key set. But I have just performed an explain on them, and it appears that the primary key is not being used, even though the field is being used in a where clause. I also notice that when I change the tables to include a compound key that it then uses the primary key. Here is one of the problematic tables:

 

create table authors (
username varchar(22) not null PRIMARY KEY,
email char(60) not null,
password char(133) not null,
website char(120) not null default '-',
account_type tinyint(1) not null default '0',
profile char(150) not null default '-'
);

 

When using:

 

EXPLAIN SELECT * FROM authors WHERE username = 'username'

 

I get this result:

 

possible_keys: NULL;

key: NULL;

ref: NULL;

rows: NULL;

extra: Impossible WHERE noticed after reading const tables;

 

This occurs on several tables. But when I change the table to this:

 

create table authors (
username varchar(22) not null,
email char(60) not null,
password char(133) not null,
website char(120) not null default '-',
account_type tinyint(1) not null default '0',
profile char(150) not null default '-',
PRIMARY KEY (username, email)
);

 

 

I get this result from the explain:

 

possible_keys: PRIMARY;

key: PRIMARY;

ref: const;

rows: 1;

extra: Using where, Using index;

 

 

Am I missing something?

 

Link to comment
Share on other sites

ok.

 

I have another question:

 

I have found somewhere else that says another optimization with a query is to use LIMIT 1, but if you are selecting from a primary key, would making it LIMIT 1 even make a difference since only 1 row is returned anyway?

 

eg:

 

"SELECT * FROM table WHERE primrykey = 'example' LIMIT 1";

 

as opposed to:

 

"SELECT * FROM table WHERE primrykey = 'example'";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.