I have the latest version of the .NET Connector. I've just started looking through the slow query log and the general query log and I'm seeing all of my joins are subselect joins. I must be doing something wrong because this can't be the quality of the .NET Connector.
If anyone is familiar with joomla and jomsocial, you'll recognize the tables in the LINQ code:
List<MessageItem> messages = (from m in context.jos_community_msg
join r in context.jos_community_msg_recepient on m.id equals r.msg_id
join u in context.jos_users on r.msg_from equals u.id
join cu in context.jos_community_users on r.msg_from equals cu.userid
where m.parent == messageId
orderby m.id
select new MessageItem()
{
Body = m.body,
IsDeleted = (r.deleted.Value == 0 ? false : true),
IsRead = (r.is_read.Value == 0 ? false : true),
MessageId = m.id,
SenderAvatar = BASE_URL + cu.thumb,
SenderId = r.msg_from,
SenderUsername = u.username,
SentDate = m.posted_on.Value,
Subject = m.subject,
SenderUserType = u.usertype
}).ToList();
What this is producing is:
SELECT
`Project1`.`C1`,
`Project1`.`body`,
`Project1`.`C2`,
`Project1`.`C3`,
`Project1`.`id`,
`Project1`.`C4`,
`Project1`.`msg_from`,
`Project1`.`username`,
`Project1`.`posted_on`,
`Project1`.`subject`,
`Project1`.`usertype`
FROM (SELECT
`Extent1`.`body`,
`Extent1`.`id`,
`Extent1`.`posted_on`,
`Extent1`.`subject`,
`Extent2`.`msg_from`,
`Extent3`.`username`,
`Extent3`.`usertype`,
1 AS `C1`,
CASE WHEN (0 = (`Extent2`.`deleted`)) THEN (cast(0 as decimal(0,0))) ELSE (cast(1 as decimal(0,0))) END AS `C2`,
CASE WHEN (0 = (`Extent2`.`is_read`)) THEN (cast(0 as decimal(0,0))) ELSE (cast(1 as decimal(0,0))) END AS `C3`,
CONCAT('http://www.mydomain.com/', `Extent4`.`thumb`) AS `C4`
FROM `jos_community_msg` AS `Extent1` INNER JOIN (SELECT
`jos_community_msg_recepient`.`bcc`,
`jos_community_msg_recepient`.`deleted`,
`jos_community_msg_recepient`.`is_read`,
`jos_community_msg_recepient`.`msg_from`,
`jos_community_msg_recepient`.`msg_id`,
`jos_community_msg_recepient`.`msg_parent`,
`jos_community_msg_recepient`.`to`
FROM `jos_community_msg_recepient` AS `jos_community_msg_recepient`) AS `Extent2` ON (`Extent1`.`id` = `Extent2`.`msg_id`) OR ((`Extent1`.`id` IS NULL) AND (`Extent2`.`msg_id` IS NULL)) INNER JOIN `jos_users` AS `Extent3` ON (`Extent2`.`msg_from` = (`Extent3`.`id`)) OR ((`Extent2`.`msg_from` IS NULL) AND (`Extent3`.`id` IS NULL)) INNER JOIN `jos_community_users` AS `Extent4` ON (`Extent2`.`msg_from` = (`Extent4`.`userid`)) OR ((`Extent2`.`msg_from` IS NULL) AND (`Extent4`.`userid` IS NULL))
WHERE `Extent1`.`parent` = 122) AS `Project1`
ORDER BY
`id` ASC
1, PRIMARY, <derived2>, ALL, , , , , 6, Using filesort
2, DERIVED, Extent1, ref, PRIMARY,parent, parent, 4, , 5,
2, DERIVED, <derived3>, ALL, , , , , 348, Using where; Using join buffer
2, DERIVED, Extent3, eq_ref, PRIMARY, PRIMARY, 4, Extent2.msg_from, 1, Using where
2, DERIVED, Extent4, eq_ref, PRIMARY, PRIMARY, 4, Extent2.msg_from, 1, Using where
3, DERIVED, jos_community_msg_recepient, ALL, , , , , 348,
What I'd expect is something like (plus the case):
select m.body, m.id, 'url' + cu.thumb, r.msg_from, u.username, m.posted_on, m.subject, u.usertype
from jos_community_msg m
join jos_community_msg_recepient r on m.id = r.msg_id
join jos_users u on r.msg_from = u.id
join jos_community_users cu on r.msg_from = cu.userid
where m.parent = 122
order by m.id
1, SIMPLE, m, ref, PRIMARY,parent, parent, 4, const, 5, Using where; Using filesort
1, SIMPLE, r, ref, un,msg_id,from, msg_id, 4, social.m.id, 1,
1, SIMPLE, u, eq_ref, PRIMARY, PRIMARY, 4, social.r.msg_from, 1, Using where
1, SIMPLE, cu, eq_ref, PRIMARY, PRIMARY, 4, social.r.msg_from, 1, Using where
What am I doing wrong?
If anyone is familiar with joomla and jomsocial, you'll recognize the tables in the LINQ code:
List<MessageItem> messages = (from m in context.jos_community_msg
join r in context.jos_community_msg_recepient on m.id equals r.msg_id
join u in context.jos_users on r.msg_from equals u.id
join cu in context.jos_community_users on r.msg_from equals cu.userid
where m.parent == messageId
orderby m.id
select new MessageItem()
{
Body = m.body,
IsDeleted = (r.deleted.Value == 0 ? false : true),
IsRead = (r.is_read.Value == 0 ? false : true),
MessageId = m.id,
SenderAvatar = BASE_URL + cu.thumb,
SenderId = r.msg_from,
SenderUsername = u.username,
SentDate = m.posted_on.Value,
Subject = m.subject,
SenderUserType = u.usertype
}).ToList();
What this is producing is:
SELECT
`Project1`.`C1`,
`Project1`.`body`,
`Project1`.`C2`,
`Project1`.`C3`,
`Project1`.`id`,
`Project1`.`C4`,
`Project1`.`msg_from`,
`Project1`.`username`,
`Project1`.`posted_on`,
`Project1`.`subject`,
`Project1`.`usertype`
FROM (SELECT
`Extent1`.`body`,
`Extent1`.`id`,
`Extent1`.`posted_on`,
`Extent1`.`subject`,
`Extent2`.`msg_from`,
`Extent3`.`username`,
`Extent3`.`usertype`,
1 AS `C1`,
CASE WHEN (0 = (`Extent2`.`deleted`)) THEN (cast(0 as decimal(0,0))) ELSE (cast(1 as decimal(0,0))) END AS `C2`,
CASE WHEN (0 = (`Extent2`.`is_read`)) THEN (cast(0 as decimal(0,0))) ELSE (cast(1 as decimal(0,0))) END AS `C3`,
CONCAT('http://www.mydomain.com/', `Extent4`.`thumb`) AS `C4`
FROM `jos_community_msg` AS `Extent1` INNER JOIN (SELECT
`jos_community_msg_recepient`.`bcc`,
`jos_community_msg_recepient`.`deleted`,
`jos_community_msg_recepient`.`is_read`,
`jos_community_msg_recepient`.`msg_from`,
`jos_community_msg_recepient`.`msg_id`,
`jos_community_msg_recepient`.`msg_parent`,
`jos_community_msg_recepient`.`to`
FROM `jos_community_msg_recepient` AS `jos_community_msg_recepient`) AS `Extent2` ON (`Extent1`.`id` = `Extent2`.`msg_id`) OR ((`Extent1`.`id` IS NULL) AND (`Extent2`.`msg_id` IS NULL)) INNER JOIN `jos_users` AS `Extent3` ON (`Extent2`.`msg_from` = (`Extent3`.`id`)) OR ((`Extent2`.`msg_from` IS NULL) AND (`Extent3`.`id` IS NULL)) INNER JOIN `jos_community_users` AS `Extent4` ON (`Extent2`.`msg_from` = (`Extent4`.`userid`)) OR ((`Extent2`.`msg_from` IS NULL) AND (`Extent4`.`userid` IS NULL))
WHERE `Extent1`.`parent` = 122) AS `Project1`
ORDER BY
`id` ASC
1, PRIMARY, <derived2>, ALL, , , , , 6, Using filesort
2, DERIVED, Extent1, ref, PRIMARY,parent, parent, 4, , 5,
2, DERIVED, <derived3>, ALL, , , , , 348, Using where; Using join buffer
2, DERIVED, Extent3, eq_ref, PRIMARY, PRIMARY, 4, Extent2.msg_from, 1, Using where
2, DERIVED, Extent4, eq_ref, PRIMARY, PRIMARY, 4, Extent2.msg_from, 1, Using where
3, DERIVED, jos_community_msg_recepient, ALL, , , , , 348,
What I'd expect is something like (plus the case):
select m.body, m.id, 'url' + cu.thumb, r.msg_from, u.username, m.posted_on, m.subject, u.usertype
from jos_community_msg m
join jos_community_msg_recepient r on m.id = r.msg_id
join jos_users u on r.msg_from = u.id
join jos_community_users cu on r.msg_from = cu.userid
where m.parent = 122
order by m.id
1, SIMPLE, m, ref, PRIMARY,parent, parent, 4, const, 5, Using where; Using filesort
1, SIMPLE, r, ref, un,msg_id,from, msg_id, 4, social.m.id, 1,
1, SIMPLE, u, eq_ref, PRIMARY, PRIMARY, 4, social.r.msg_from, 1, Using where
1, SIMPLE, cu, eq_ref, PRIMARY, PRIMARY, 4, social.r.msg_from, 1, Using where
What am I doing wrong?