I have a below table structure for friends 开发者_高级运维table
TABLE STRUCTURE
CREATE TABLE `my_friends` (
`first_user_id` int(10) unsigned NOT NULL,
`second_user_id` int(10) unsigned NOT NULL,
`approved` tinyint(1) NOT NULL DEFAULT '0',
`request_sent` int(10) unsigned DEFAULT NULL,
`request_approved` int(10) unsigned DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
and
DATA
insert into `my_friends` values (4,1,1,null,null);
insert into `my_friends` values (7,8,1,null,null);
insert into `my_friends` values (1,7,1,null,null);
insert into `my_friends` values (2,7,1,null,null);
insert into `my_friends` values (4,2,1,null,null);
To get all the friends for user id "1" , I am running the below query
QUERY TO GET FRIENDS
SELECT first_user_id user_id, second_user_id friend_id from my_friends where first_user_id=1 and approved=1
union
SELECT second_user_id user_id ,first_user_id friend_id from my_friends where second_user_id=1 and approved=1
and when I check explain plan for this , this throws
EXPLAIN PLAN ERROR
Error
Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
I am using this query in most of the queries as a subquery and this one causing the issue to check explain plan for all other queries
This is an issue with Mysql and raised with mysql
精彩评论