1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
| --------------
SET AUTOCOMMIT = 0
--------------
--------------
START TRANSACTION
--------------
--------------
SET collation_connection = latin1_general_ci
--------------
--------------
DROP DATABASE IF EXISTS `bv`
--------------
--------------
CREATE DATABASE `bv`
DEFAULT CHARACTER SET `latin1`
DEFAULT COLLATE `latin1_general_ci`
--------------
--------------
DROP TABLE IF EXISTS `paper`
--------------
--------------
CREATE TABLE `paper`
( `id` integer unsigned not null auto_increment primary key,
`status` tinyint unsigned not null,
`code_client` char(06) not null,
`code_document` char(07) not null,
`num_matricule` char(06) not null,
`enreg` varchar(255) not null,
index `idx_1` (`code_document`)
) ENGINE=MyIsam
DEFAULT CHARSET=`latin1` COLLATE=`latin1_general_ci`
ROW_FORMAT=COMPRESSED
--------------
--------------
insert into `paper` (`code_document`,`code_client`,`num_matricule`,`status`,`enreg`) values
('D751000','850001','000001',1,'enreg'),
('xxxxxxx','850013','000013',0,'enreg'),
('xxxxxxx','850014','000014',1,'enreg'),
('D751001','850002','000002',1,'enreg'),
('xxxxxxx','850015','000015',0,'enreg'),
('xxxxxxx','850016','000016',1,'enreg'),
('D751010','850003','000003',1,'enreg'),
('xxxxxxx','850017','000017',0,'enreg'),
('xxxxxxx','850018','000018',1,'enreg'),
('D751020','850004','000004',1,'enreg'),
('ooooooo','850019','000019',0,'enreg'),
('ooooooo','850020','000020',1,'enreg'),
('D801000','850005','000005',1,'enreg'),
('ooooooo','850021','000021',0,'enreg'),
('ooooooo','850022','000022',1,'enreg'),
('D801001','850006','000006',1,'enreg'),
('ooooooo','850023','000023',0,'enreg'),
('ooooooo','850024','000024',1,'enreg'),
('G100010','850007','000007',1,'enreg'),
('ooooooo','850025','000025',0,'enreg'),
('ooooooo','850026','000026',1,'enreg'),
('G100025','850008','000008',1,'enreg'),
('ooooooo','850027','000027',0,'enreg'),
('ooooooo','850028','000028',0,'enreg'),
('G100030','850009','000009',1,'enreg'),
('ooooooo','850029','000029',0,'enreg'),
('ooooooo','850030','000030',0,'enreg'),
('G100035','850010','000010',1,'enreg'),
('ooooooo','850031','000031',0,'enreg'),
('ooooooo','850032','000032',0,'enreg'),
('G100040','850011','000011',1,'enreg'),
('ooooooo','850033','000033',0,'enreg'),
('ooooooo','850034','000034',0,'enreg'),
('G100045','850012','000012',1,'enreg')
--------------
--------------
select * from `paper`
--------------
+----+--------+-------------+---------------+---------------+-------+
| id | status | code_client | code_document | num_matricule | enreg |
+----+--------+-------------+---------------+---------------+-------+
| 1 | 1 | 850001 | D751000 | 000001 | enreg |
| 2 | 0 | 850013 | xxxxxxx | 000013 | enreg |
| 3 | 1 | 850014 | xxxxxxx | 000014 | enreg |
| 4 | 1 | 850002 | D751001 | 000002 | enreg |
| 5 | 0 | 850015 | xxxxxxx | 000015 | enreg |
| 6 | 1 | 850016 | xxxxxxx | 000016 | enreg |
| 7 | 1 | 850003 | D751010 | 000003 | enreg |
| 8 | 0 | 850017 | xxxxxxx | 000017 | enreg |
| 9 | 1 | 850018 | xxxxxxx | 000018 | enreg |
| 10 | 1 | 850004 | D751020 | 000004 | enreg |
| 11 | 0 | 850019 | ooooooo | 000019 | enreg |
| 12 | 1 | 850020 | ooooooo | 000020 | enreg |
| 13 | 1 | 850005 | D801000 | 000005 | enreg |
| 14 | 0 | 850021 | ooooooo | 000021 | enreg |
| 15 | 1 | 850022 | ooooooo | 000022 | enreg |
| 16 | 1 | 850006 | D801001 | 000006 | enreg |
| 17 | 0 | 850023 | ooooooo | 000023 | enreg |
| 18 | 1 | 850024 | ooooooo | 000024 | enreg |
| 19 | 1 | 850007 | G100010 | 000007 | enreg |
| 20 | 0 | 850025 | ooooooo | 000025 | enreg |
| 21 | 1 | 850026 | ooooooo | 000026 | enreg |
| 22 | 1 | 850008 | G100025 | 000008 | enreg |
| 23 | 0 | 850027 | ooooooo | 000027 | enreg |
| 24 | 0 | 850028 | ooooooo | 000028 | enreg |
| 25 | 1 | 850009 | G100030 | 000009 | enreg |
| 26 | 0 | 850029 | ooooooo | 000029 | enreg |
| 27 | 0 | 850030 | ooooooo | 000030 | enreg |
| 28 | 1 | 850010 | G100035 | 000010 | enreg |
| 29 | 0 | 850031 | ooooooo | 000031 | enreg |
| 30 | 0 | 850032 | ooooooo | 000032 | enreg |
| 31 | 1 | 850011 | G100040 | 000011 | enreg |
| 32 | 0 | 850033 | ooooooo | 000033 | enreg |
| 33 | 0 | 850034 | ooooooo | 000034 | enreg |
| 34 | 1 | 850012 | G100045 | 000012 | enreg |
+----+--------+-------------+---------------+---------------+-------+
--------------
DROP DATABASE IF EXISTS `bvr`
--------------
--------------
CREATE DATABASE `bvr`
DEFAULT CHARACTER SET `latin1`
DEFAULT COLLATE `latin1_general_ci`
--------------
--------------
DROP TABLE IF EXISTS `indiv`
--------------
--------------
CREATE TABLE `indiv`
( `id` integer unsigned not null auto_increment primary key,
`code_client` char(06) not null,
`num_matricule` char(06) not null,
`status` tinyint unsigned not null,
index `idx_2` (`code_client`,`num_matricule`)
) ENGINE=MyIsam
DEFAULT CHARSET=`latin1` COLLATE=`latin1_general_ci`
ROW_FORMAT=COMPRESSED
--------------
--------------
insert into `indiv` (`code_client`,`num_matricule`,`status`) values
('850001','000001',1),
('850002','000002',1),
('850003','000003',1),
('850004','000004',1),
('850005','000005',1),
('850006','000006',1),
('850007','000007',1),
('850008','000008',1),
('850009','000009',1),
('850010','000010',1),
('850011','000011',1),
('850012','000012',1)
--------------
--------------
select * from `indiv`
--------------
+----+-------------+---------------+--------+
| id | code_client | num_matricule | status |
+----+-------------+---------------+--------+
| 1 | 850001 | 000001 | 1 |
| 2 | 850002 | 000002 | 1 |
| 3 | 850003 | 000003 | 1 |
| 4 | 850004 | 000004 | 1 |
| 5 | 850005 | 000005 | 1 |
| 6 | 850006 | 000006 | 1 |
| 7 | 850007 | 000007 | 1 |
| 8 | 850008 | 000008 | 1 |
| 9 | 850009 | 000009 | 1 |
| 10 | 850010 | 000010 | 1 |
| 11 | 850011 | 000011 | 1 |
| 12 | 850012 | 000012 | 1 |
+----+-------------+---------------+--------+
--------------
select *
FROM bv.paper as i0_
LEFT JOIN bvr.indiv as iin
ON i0_.num_matricule = iin.num_matricule
AND i0_.code_client = iin.code_client
AND i0_.num_matricule IS NOT NULL
WHERE (( (( i0_.code_document IN ('D751001','D751010','D751020','D751000','D801000','D801001'))
AND ((i0_.code_client <= '852146')
OR (iin.code_client <= '852146')))
OR (( i0_.code_document IN ('G100035','G100040','G100030','G100025','G100010'))
AND ( i0_.code_client <= '852146')))
AND ( i0_.status = 1 )
AND ( i0_.code_document IN ('G100035','G100040','G100045','G100030','G100025')))
--------------
+----+--------+-------------+---------------+---------------+-------+------+-------------+---------------+--------+
| id | status | code_client | code_document | num_matricule | enreg | id | code_client | num_matricule | status |
+----+--------+-------------+---------------+---------------+-------+------+-------------+---------------+--------+
| 22 | 1 | 850008 | G100025 | 000008 | enreg | 8 | 850008 | 000008 | 1 |
| 25 | 1 | 850009 | G100030 | 000009 | enreg | 9 | 850009 | 000009 | 1 |
| 28 | 1 | 850010 | G100035 | 000010 | enreg | 10 | 850010 | 000010 | 1 |
| 31 | 1 | 850011 | G100040 | 000011 | enreg | 11 | 850011 | 000011 | 1 |
+----+--------+-------------+---------------+---------------+-------+------+-------------+---------------+--------+
--------------
explain
SELECT COUNT(bv.i0_.enreg) AS sclr_0
FROM bv.paper as i0_
LEFT JOIN bvr.indiv as iin
ON i0_.num_matricule = iin.num_matricule
AND i0_.code_client = iin.code_client
AND i0_.num_matricule IS NOT NULL
WHERE (( (( i0_.code_document IN ('D751001','D751010','D751020','D751000','D801000','D801001'))
AND ((i0_.code_client <= '852146')
OR (iin.code_client <= '852146')))
OR (( i0_.code_document IN ('G100035','G100040','G100030','G100025','G100010'))
AND ( i0_.code_client <= '852146')))
AND ( i0_.status = 1 )
AND ( i0_.code_document IN ('G100035','G100040','G100045','G100030','G100025')))
--------------
+----+-------------+-------+------------+-------+---------------+-------+---------+-----------------------------------------+------+----------+------------------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+-------+------------+-------+---------------+-------+---------+-----------------------------------------+------+----------+------------------------------------+
| 1 | SIMPLE | i0_ | NULL | range | idx_1 | idx_1 | 7 | NULL | 4 | 10.00 | Using index condition; Using where |
| 1 | SIMPLE | iin | NULL | ref | idx_2 | idx_2 | 12 | bv.i0_.code_client,bv.i0_.num_matricule | 2 | 100.00 | Using where; Using index |
+----+-------------+-------+------------+-------+---------------+-------+---------+-----------------------------------------+------+----------+------------------------------------+
--------------
select *
FROM bv.paper as i0_
LEFT JOIN bvr.indiv as iin
ON i0_.num_matricule = iin.num_matricule
AND i0_.code_client = iin.code_client
AND i0_.num_matricule IS NOT NULL
where i0_.status = 1
AND i0_.code_client <= '852146'
AND i0_.code_document IN ('G100025','G100030','G100035','G100040')
--------------
+----+--------+-------------+---------------+---------------+-------+------+-------------+---------------+--------+
| id | status | code_client | code_document | num_matricule | enreg | id | code_client | num_matricule | status |
+----+--------+-------------+---------------+---------------+-------+------+-------------+---------------+--------+
| 22 | 1 | 850008 | G100025 | 000008 | enreg | 8 | 850008 | 000008 | 1 |
| 25 | 1 | 850009 | G100030 | 000009 | enreg | 9 | 850009 | 000009 | 1 |
| 28 | 1 | 850010 | G100035 | 000010 | enreg | 10 | 850010 | 000010 | 1 |
| 31 | 1 | 850011 | G100040 | 000011 | enreg | 11 | 850011 | 000011 | 1 |
+----+--------+-------------+---------------+---------------+-------+------+-------------+---------------+--------+
--------------
COMMIT
--------------
--------------
SET AUTOCOMMIT = 1
--------------
Appuyez sur une touche pour continuer... |
Partager