Skip to content

Instantly share code, notes, and snippets.

View tistaharahap's full-sized avatar

Batista Harahap tistaharahap

View GitHub Profile
$ pip install -r requirements.txt
Collecting python-handler-socket (from -r deps (line 1))
Downloading python-handler-socket-0.2.4.tar.gz
Building wheels for collected packages: python-handler-socket
Running setup.py bdist_wheel for python-handler-socket ... done
Stored in directory: /Users/tista/Library/Caches/pip/wheels/48/7c/46/ee1c1e3dabc22527c8780ac7ae3ca7ba03a66e6720d5d1f481
Successfully built python-handler-socket
Installing collected packages: python-handler-socket
Successfully installed python-handler-socket-0.2.4
python-handler-socket
CREATE TABLE user (
user_id INT UNSIGNED PRIMARY KEY,
user_name VARCHAR(50),
user_email VARCHAR(255),
created DATETIME
) ENGINE=InnoDB;
It may not seem like it, but there’s a lot of information packed into those 10 columns! The columns returned by the query are:
id – a sequential identifier for each SELECT within the query (for when you have nested subqueries)
select_type – the type of SELECT query. Possible values are:
SIMPLE – the query is a simple SELECT query without any subqueries or UNIONs
PRIMARY – the SELECT is in the outermost query in a JOIN
DERIVED – the SELECT is part of a subquery within a FROM clause
SUBQUERY – the first SELECT in a subquery
DEPENDENT SUBQUERY – a subquery which is dependent upon on outer query
UNCACHEABLE SUBQUERY – a subquery which is not cacheable (there are certain conditions for a query to be cacheable)
MariaDB [fun]> EXPLAIN SELECT * FROM users WHERE first_name = 'Martin' AND last_name = 'David';
+------+-------------+-------+------+----------------------+----------------------+---------+-------------+------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+------+----------------------+----------------------+---------+-------------+------+--------------------------+
| 1 | SIMPLE | users | ref | first_and_last_names | first_and_last_names | 106 | const,const | 1 | Using where; Using index |
+------+-------------+-------+------+----------------------+----------------------+---------+-------------+------+--------------------------+
1 row in set (0.00 sec)
MariaDB [fun]> CREATE INDEX first_and_last_names ON users (first_name, last_name);
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
MariaDB [fun]> EXPLAIN SELECT * FROM users WHERE first_name = 'Martin' AND last_name = 'David';
+------+-------------+-------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | users | ALL | NULL | NULL | NULL | NULL | 10 | Using where |
+------+-------------+-------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)
MariaDB [fun]> SELECT * FROM names WHERE first_name = 'Martin' AND last_name = 'David';
+----+------------+-----------+
| id | first_name | last_name |
+----+------------+-----------+
| 10 | Martin | David |
+----+------------+-----------+
1 row in set (0.01 sec)
MariaDB [fun]> SELECT * FROM names;
+----+------------+------------+
| id | first_name | last_name |
+----+------------+------------+
| 1 | Batista | Harahap |
| 2 | Rinto | Harahap |
| 3 | Michael | Jordan |
| 4 | Chris | Martin |
| 5 | Jordan | Sparks |
| 6 | Daniel | Craig |
$ python cythondemo.py
Elapsed Time: 3.86 second
Ops/second: 25903031.00