を最適化するまで、私はこのテーブルを持っている:誤った結果を与えるMY-SQLテーブル、クエリ、私はテーブル
CREATE TABLE `posts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`origin_post_id` int(11) NOT NULL,
`ref_post_id` int(11) NOT NULL,
`broker_user_id` int(11) NOT NULL,
`isshared` tinyint(4) NOT NULL,
`type` tinyint(4) NOT NULL,
`deal_type` tinyint(4) NOT NULL,
`title` varchar(200) NOT NULL,
`currency` varchar(10) NOT NULL,
`country_code` varchar(10) NOT NULL,
`price` float(10,2) NOT NULL,
`price_to` float(10,2) NOT NULL,
`sector` int(11) NOT NULL,
`protype` int(11) NOT NULL,
`sea_view` int(11) NOT NULL,
`sea_view_to` int(11) NOT NULL,
`area` int(11) NOT NULL,
`area_to` int(11) NOT NULL,
`area_mesure_type` tinyint(4) NOT NULL DEFAULT '1',
`building_area` int(11) NOT NULL,
`building_area_to` int(11) NOT NULL,
`building_area_mesure_type` tinyint(4) NOT NULL DEFAULT '1',
`bathrooms` int(11) NOT NULL,
`bathrooms_to` int(11) NOT NULL,
`rooms` int(11) NOT NULL,
`rooms_to` int(11) NOT NULL,
`location` varchar(300) NOT NULL,
`lat` float NOT NULL,
`lng` float NOT NULL,
`description` text NOT NULL,
`map_data` varchar(500) NOT NULL,
`shape_data` text NOT NULL,
`seo_title` varchar(300) NOT NULL,
`seo_keywords` varchar(300) NOT NULL,
`seo_description` varchar(300) NOT NULL,
`status` tinyint(4) NOT NULL,
`publish_date` date NOT NULL,
`expiry_date` date NOT NULL,
`request_status` enum('','NEW','ACCEPTED','REJECTED') NOT NULL,
`request_date` date NOT NULL,
`accept_date` date NOT NULL,
`share_per` float(5,2) NOT NULL,
`deal_completed` tinyint(4) NOT NULL,
`completed_by` int(11) NOT NULL,
`created` datetime NOT NULL,
`updated` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `type` (`type`),
KEY `deal_type` (`deal_type`),
KEY `price` (`price`),
KEY `sector` (`sector`),
KEY `protype` (`protype`),
KEY `sea_view` (`sea_view`),
KEY `area` (`area`),
KEY `building_area` (`building_area`),
KEY `bathrooms` (`bathrooms`),
KEY `rooms` (`rooms`),
KEY `lat` (`lat`),
KEY `lng` (`lng`),
KEY `status` (`status`),
KEY `price_to` (`price_to`),
KEY `sea_view_to` (`sea_view_to`),
KEY `area_to` (`area_to`),
KEY `building_area_to` (`building_area_to`),
KEY `bathrooms_to` (`bathrooms_to`),
KEY `rooms_to` (`rooms_to`),
KEY `request_status` (`request_status`),
KEY `request_date` (`request_date`),
KEY `accept_date` (`accept_date`),
KEY `ref_post_id` (`ref_post_id`),
KEY `deal_completed` (`deal_completed`),
KEY `location` (`location`(255)),
KEY `user_id` (`user_id`),
KEY `country_code` (`country_code`),
KEY `expiry_date` (`expiry_date`),
KEY `origin_post_id` (`origin_post_id`),
KEY `completed_by` (`completed_by`),
FULLTEXT KEY `title_location_description` (`title`,`location`,`description`),
CONSTRAINT `posts_ibfk_3` FOREIGN KEY (`user_id`) REFERENCES `app_users` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=833 DEFAULT CHARSET=utf8
私はその後、select count(id) from posts where deal_completed='1' and user_id='<anyuserid>'
を実行すると、それは常にゼロレコードを与えますが、私はこのテーブルを最適化するとき、それは正しい結果を与えていますしばらくしてから、テーブルを最適化するためにもう一度必要となります。
問題の再現可能な例を投稿できますか? –
テーブルの最適化はデータを変更してはいけません。もっと重要なことに、 'group by 'を持たない集約クエリは常に* 1つの行を返さなければなりません。 *列*の値は0でも構いませんが、レコードの数は常に1になります。 –
価格は決してFLOATではありません。 DECIMALが発明された理由です – Strawberry