set @row_number = 0;
SELECT
*
FROM
(SELECT
(@row_number:=@row_number + 1) AS num,
id,
tbl_user_id,
title,
description,
length lengths,
create_date,
file_size,
thumbnails,
videos.itsOK,
viewed
FROM
tbl_videos videos
WHERE
videos.tbl_user_id = 23
AND videos.tbl_category_id = 265
ORDER BY videos.create_date DESC
) AS paginateTbl
WHERE
paginateTbl.num > 0
&& paginateTbl.num <= 9
内部查询对它们都有效,但主要查询仅在 mariadb 中有效!mysql不工作是怎么回事?
使用的版本是 mysql:5.5.44-0ubuntu0.14.04.1
和 mariadb 10.0.13-MariaDB-log
。
语句是相同的CREATE TABLE
(除了AUTO_INCREMENT
, 行数):
MySQL结果:
SHOW CREATE TABLE tbl_videos;
CREATE TABLE `tbl_videos` (
`id` INT (20) NOT NULL AUTO_INCREMENT
,`title` VARCHAR(255) COLLATE utf8_persian_ci NOT NULL
,`description` TEXT COLLATE utf8_persian_ci NOT NULL
,`tags` TEXT COLLATE utf8_persian_ci NOT NULL
,`video_quality` VARCHAR(255) COLLATE utf8_persian_ci NOT NULL
,`dl_link1` VARCHAR(255) COLLATE utf8_persian_ci NOT NULL
,`dl_link2` VARCHAR(255) COLLATE utf8_persian_ci NOT NULL
,`dl_link3` VARCHAR(255) COLLATE utf8_persian_ci NOT NULL
,`viewed` INT (11) NOT NULL
,`viewed_duration` VARCHAR(255) COLLATE utf8_persian_ci NOT NULL
,`viewed_traffic` VARCHAR(255) COLLATE utf8_persian_ci NOT NULL
,`embed_code` VARCHAR(255) COLLATE utf8_persian_ci NOT NULL
,`sharing_code` VARCHAR(255) COLLATE utf8_persian_ci NOT NULL
,`replace_times` INT (11) NOT NULL
,`actual_link` TEXT COLLATE utf8_persian_ci NOT NULL
,`tbl_user_id` INT (11) NOT NULL
,`tbl_category_id` INT (11) NOT NULL
,`tbl_player_id` INT (11) NOT NULL
,`itsOK` TINYINT (2) NOT NULL
,`length` INT (20) NOT NULL
,`create_date` INT (11) NOT NULL
,`modified_date` INT (11) NOT NULL
,`thumbnails` TEXT COLLATE utf8_persian_ci
,`serverId` VARCHAR(32) COLLATE utf8_persian_ci NOT NULL
,`sizes` VARCHAR(100) COLLATE utf8_persian_ci DEFAULT NULL
,`our_server_link` VARCHAR(255) COLLATE utf8_persian_ci DEFAULT NULL
,`like` INT (11) NOT NULL DEFAULT '0'
,`file_size` FLOAT DEFAULT NULL
,`islogo` TEXT COLLATE utf8_persian_ci
,`uuid` VARCHAR(64) COLLATE utf8_persian_ci DEFAULT NULL
,`output_type` VARCHAR(255) COLLATE utf8_persian_ci DEFAULT NULL
,`video_file` VARCHAR(255) COLLATE utf8_persian_ci DEFAULT NULL
,`video_setting` TEXT COLLATE utf8_persian_ci NOT NULL
,`soft_hard` VARCHAR(255) COLLATE utf8_persian_ci DEFAULT NULL
,`soft_hard_logo` VARCHAR(255) COLLATE utf8_persian_ci NOT NULL
,`vastTag` TEXT COLLATE utf8_persian_ci
,`extra_cat_id` INT (11) NOT NULL DEFAULT '0'
,`all_terafic` BIGINT (20) NOT NULL DEFAULT '0'
,PRIMARY KEY (`id`)
,KEY `tbl_user_id`(`tbl_user_id`)
,KEY `tbl_category_id`(`tbl_category_id`)
,CONSTRAINT `tbl_videos_ibfk_1` FOREIGN KEY (`tbl_user_id`) REFERENCES `tbl_users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE
,CONSTRAINT `tbl_videos_ibfk_2` FOREIGN KEY (`tbl_category_id`) REFERENCES `tbl_categories`(`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE = InnoDB AUTO_INCREMENT = 4622 DEFAULT CHARSET = utf8 COLLATE = utf8_persian_ci
MariaDB 结果:
SHOW CREATE TABLE tbl_videos;
CREATE TABLE `tbl_videos` (
`id` INT (20) NOT NULL AUTO_INCREMENT
,`title` VARCHAR(255) COLLATE utf8_persian_ci NOT NULL
,`description` TEXT COLLATE utf8_persian_ci NOT NULL
,`tags` TEXT COLLATE utf8_persian_ci NOT NULL
,`video_quality` VARCHAR(255) COLLATE utf8_persian_ci NOT NULL
,`dl_link1` VARCHAR(255) COLLATE utf8_persian_ci NOT NULL
,`dl_link2` VARCHAR(255) COLLATE utf8_persian_ci NOT NULL
,`dl_link3` VARCHAR(255) COLLATE utf8_persian_ci NOT NULL
,`viewed` INT (11) NOT NULL
,`viewed_duration` VARCHAR(255) COLLATE utf8_persian_ci NOT NULL
,`viewed_traffic` VARCHAR(255) COLLATE utf8_persian_ci NOT NULL
,`embed_code` VARCHAR(255) COLLATE utf8_persian_ci NOT NULL
,`sharing_code` VARCHAR(255) COLLATE utf8_persian_ci NOT NULL
,`replace_times` INT (11) NOT NULL
,`actual_link` TEXT COLLATE utf8_persian_ci NOT NULL
,`tbl_user_id` INT (11) NOT NULL
,`tbl_category_id` INT (11) NOT NULL
,`tbl_player_id` INT (11) NOT NULL
,`itsOK` TINYINT (2) NOT NULL
,`length` INT (20) NOT NULL
,`create_date` INT (11) NOT NULL
,`modified_date` INT (11) NOT NULL
,`thumbnails` TEXT COLLATE utf8_persian_ci
,`serverId` VARCHAR(32) COLLATE utf8_persian_ci NOT NULL
,`sizes` VARCHAR(100) COLLATE utf8_persian_ci DEFAULT NULL
,`our_server_link` VARCHAR(255) COLLATE utf8_persian_ci DEFAULT NULL
,`like` INT (11) NOT NULL DEFAULT '0'
,`file_size` FLOAT DEFAULT NULL
,`islogo` TEXT COLLATE utf8_persian_ci
,`uuid` VARCHAR(64) COLLATE utf8_persian_ci DEFAULT NULL
,`output_type` VARCHAR(255) COLLATE utf8_persian_ci DEFAULT NULL
,`video_file` VARCHAR(255) COLLATE utf8_persian_ci DEFAULT NULL
,`video_setting` TEXT COLLATE utf8_persian_ci NOT NULL
,`soft_hard` VARCHAR(255) COLLATE utf8_persian_ci DEFAULT NULL
,`soft_hard_logo` VARCHAR(255) COLLATE utf8_persian_ci NOT NULL
,`vastTag` TEXT COLLATE utf8_persian_ci
,`extra_cat_id` INT (11) NOT NULL DEFAULT '0'
,`all_terafic` BIGINT (20) NOT NULL DEFAULT '0'
,PRIMARY KEY (`id`)
,KEY `tbl_user_id`(`tbl_user_id`)
,KEY `tbl_category_id`(`tbl_category_id`)
,CONSTRAINT `tbl_videos_ibfk_1` FOREIGN KEY (`tbl_user_id`) REFERENCES `tbl_users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE
,CONSTRAINT `tbl_videos_ibfk_2` FOREIGN KEY (`tbl_category_id`) REFERENCES `tbl_categories`(`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE = InnoDB AUTO_INCREMENT = 9387 DEFAULT CHARSET = utf8 COLLATE = utf8_persian_ci
mysql结果:
EXPLAIN SELECT * from FROM ...
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 14 Using where
2 DERIVED videos index_merge tbl_user_id,tbl_category_id tbl_category_id,tbl_user_id 4,4 NULL 1 Using intersect(tbl_category_id,tbl_user_id); Using where; Using filesort
mariadb 结果:
EXPLAIN SELECT * from tbl_videos
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 Using where
2 DERIVED videos index_merge tbl_user_id,tbl_category_id tbl_category_id,tbl_user_id 4,4 NULL 1 Using intersect(tbl_category_id,tbl_user_id); Using where; Using filesort