Skip to content

Instantly share code, notes, and snippets.

EXPLAIN SELECT * FROM products WHERE is_deleted = 0 AND status = 'ordered';
EXPLAIN SELECT * FROM products WHERE is_deleted = 0 AND status = 'ordered';
SET autocommit=0;
INSERT INTO products (name, status) VALUES
('Product 1', 'live'),
...
('Product 10', 'live');
COMMIT;
ALTER TABLE `products` DISABLE KEYS;
INSERT INTO products (name, status) VALUES
('Product 1', 'live'),
...
('Product 10', 'live');
ALTER TABLE `products` ENABLE KEYS;
<?php
$aCity = new \stdClass();
$aCity->name = 'Hamburg';
$object = new \stdClass();
$object->name = 'Marcel';
$object->cities = [$aCity];
echo data_get($object, 'name');
<?php
if (!empty($data['more']['complex'][0])) {
echo 'This code will never be executed';
}
<?php
$data = [
'more' => [
'complex' => ['my value']
]
];
if (array_key_exists('more', $data) && array_key_exists('complex', $data['more']) && array_key_exists(0, $data['more']['complex'])) {
<?php
$data = ['likes' => 'Laravel'];
$object = new stdClass();
$object->name = 'Marcel';
$object->city = 'Hamburg';
if (property_exists($object, 'name')) {
echo $object->name;
}
CREATE TABLE `products` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci,
`status` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT '',
`is_deleted` TINYINT(1) DEFAULT '0'
) ENGINE=InnoDB;
-- Performance check if the index is hit
SET @start_time = NOW();
SELECT * FROM products WHERE is_deleted = 0 AND status = 'ordered';
SET @end_time = NOW();
 
SELECT TIMEDIFF(@end_time, @start_time) AS difference;