Description:
I referenced an illegal column in a subquery and instead of firing an exception it was treated as a null set:
mysql> select * from assets where parent_id=4490 and id not in (select id from network_ports);
Empty set (0.00 sec)
mysql> select id from network_ports;
ERROR 1054 (42S22): Unknown column 'id' in 'field list'
I had a fellow #mysql'er verify on his server.
How to repeat:
#
mysql> show create table network_ports\G
#
*************************** 1. row ***************************
#
Table: network_ports
#
Create Table: CREATE TABLE `network_ports` (
#
`asset_id` int(11) NOT NULL default '0',
#
`mac_addr` varchar(17) default NULL,
#
`if_name` varchar(255) default NULL,
#
`dev_name` varchar(255) default NULL,
#
`switch_id` int(11) default NULL,
#
`port_phys` varchar(255) default NULL,
#
`port_virt` int(11) default NULL,
#
`stamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
#
PRIMARY KEY (`asset_id`),
#
UNIQUE KEY `mac_addr` (`mac_addr`),
#
KEY `switch_id` (`switch_id`),
#
CONSTRAINT `network_ports_ibfk_1` FOREIGN KEY (`asset_id`) REFERENCES `assets` (`id`) ON DELETE CASCADE,
#
CONSTRAINT `network_ports_ibfk_2` FOREIGN KEY (`switch_id`) REFERENCES `switches` (`asset_id`) ON DELETE SET NULL
#
) ENGINE=InnoDB DEFAULT CHARSET=latin1
#
1 row in set (0.00 sec)
#
#
#
ysql> show create table assets\G
#
*************************** 1. row ***************************
#
Table: assets
#
Create Table: CREATE TABLE `assets` (
#
`id` int(11) NOT NULL auto_increment,
#
`asset_def_id` int(11) NOT NULL default '0',
#
`natnet_serial` varchar(255) default NULL,
#
`vendor_serial` varchar(255) default NULL,
#
`manu_serial` varchar(255) default NULL,
#
`po_id` int(11) default NULL,
#
`owner_account_id` int(11) NOT NULL default '3781',
#
`location_id` int(11) default NULL,
#
`date_start` datetime default NULL,
#
`date_end` datetime default NULL,
#
`date_acquired` datetime default NULL,
#
`status_id` int(11) NOT NULL default '0',
#
`account_id` int(11) NOT NULL default '0',
#
`parent_id` int(11) default NULL,
#
`date_modified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
#
PRIMARY KEY (`id`),
#
UNIQUE KEY `natnet_serial` (`natnet_serial`),
#
UNIQUE KEY `vendor_serial` (`vendor_serial`),
#
UNIQUE KEY `manu_serial` (`manu_serial`),
#
KEY `asset_def_id` (`asset_def_id`),
#
KEY `po_id` (`po_id`),
#
KEY `location_id` (`location_id`),
#
KEY `status_id` (`status_id`),
#
KEY `account_id` (`account_id`),
#
KEY `parent_id` (`parent_id`),
#
KEY `owner_account_id` (`owner_account_id`),
#
CONSTRAINT `assets_ibfk_1` FOREIGN KEY (`asset_def_id`) REFERENCES `asset_defs` (`id`),
#
CONSTRAINT `assets_ibfk_3` FOREIGN KEY (`owner_account_id`) REFERENCES `accounts` (`id`),
#
CONSTRAINT `assets_ibfk_4` FOREIGN KEY (`location_id`) REFERENCES `locations` (`id`),
#
CONSTRAINT `assets_ibfk_5` FOREIGN KEY (`status_id`) REFERENCES `asset_statuses` (`id`),
#
CONSTRAINT `assets_ibfk_6` FOREIGN KEY (`account_id`) REFERENCES `accounts` (`id`),
#
CONSTRAINT `assets_ibfk_7` FOREIGN KEY (`parent_id`) REFERENCES `assets` (`id`) ON DELETE CASCADE
#
) ENGINE=InnoDB DEFAULT CHARSET=latin1
#
1 row in set (0.00 sec)
#
#
mysql> select * from assets where parent_id=4490 and id not in (select id from network_ports);
#
Empty set (0.00 sec)
#
#
mysql> select id from network_ports;
ERROR 1054 (42S22): Unknown column 'id' in 'field list'
Suggested fix:
Should throw ERROR 1054 (42S22): Unknown column 'id' in 'field list'