- OS: Debian 12 VM on Proxmox VE 8
- CPUs: 8x Xeon E5-2620 v2
- RAM: 8 GiB DDR3
- HDD: Samsung PM863 NVMe in Ceph over Mellanox Infiniband 56 Gbps IPoIB
- Virtualized via
scsi-virtio-single
,aio=native
,io_threads=enabled
- Virtualized via
- FS: ext4
(rw,noatime)
MySQL's documentation states:
When combining LIMIT row_count with DISTINCT, MySQL stops as soon as it finds row_count unique rows.
The question was asked, how is this deterministic / accurate? My hypothesis is that it's due to MySQL's use of a clustering
index, as opposed to Postgres' heap storage. I think that, given a monotonic PK such as an AUTO_INCREMENT
(or perhaps
any index), it's able to use that to guarantee determinism.
This table has 1,000,000 rows, consisting of a UUIDv4 PK, a random int of range (1,1000000), and ~1 KiB of Lorem Ipsum text.
postgres=# \d+ uuid_pk
Table "public.uuid_pk"
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
---------+---------+-----------+----------+---------+----------+-------------+--------------+-------------
id | uuid | | not null | | plain | | |
user_id | integer | | not null | | plain | | |
lorem | text | | not null | | extended | | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET search_path TO 'example'; | |
INSERT INTO genre (name) VALUES ('Rock'), ('Classic Rock'), ('Metal'), ('Progressive Metal'), ('Arena Rock'), ('Alternative Metal'), ('Grunge'); | |
INSERT INTO category (name) VALUES ('Book'), ('Music'); | |
INSERT INTO format (name) VALUES ('Compact Disc'), ('Vinyl'); | |
INSERT INTO band (year_formed, name) VALUES (1985, 'Majesty'), (1988, 'Dream Theater'), (1990, 'Tool'), (1970, 'Queen'), (1987, 'Alice in Chains'); | |
INSERT INTO artist (first_name, last_name) VALUES ('John', 'Petrucci'), ('John', 'Myung'), ('James', 'LaBrie'), ('Jordan', 'Ruddess'), ('Mike', 'Portnoy'), ('Mike', 'Mangini'); | |
INSERT INTO artist (first_name, last_name, prefix, suffix) VALUES ('Brian', 'May', 'Sir', 'CBE'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Calculates various parameters for the InnoDB buffer pool based on a simple input. | |
The InnoDB engine is extremely strict about how its buffer pool can be sized. | |
Ref: https://dev.mysql.com/doc/refman/8.0/en/innodb-parameters.html#sysvar_innodb_buffer_pool_chunk_size | |
Other than size restrictions (which are unlikely to be violated in normal practice), there are | |
complicated relationships between the three main variables that must be met, plus some | |
best practices to be observed. Getting these three correct can be challenging, hence this calculator. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql> CREATE TABLE foo(id TINYINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, bar BINARY(16), baz CHAR(36)); | |
Query OK, 0 rows affected (0.03 sec) | |
mysql> INSERT INTO foo (bar, baz) VALUES (UUID_TO_BIN('dc23a9b9-a129-11ee-95fb-0242ac110000'), 'dc23a9b9-a129-11ee-95fb-0242ac110000'); | |
Query OK, 1 row affected (0.02 sec) | |
mysql> INSERT INTO foo (bar, baz) VALUES (UUID_TO_BIN('dc23a9b9-a129-11ee-95fb-0242ac110000'), 'dc23a9b9a12911ee95fb0242ac110000'); | |
Query OK, 1 row affected (0.01 sec) | |
mysql> SHOW BINARY LOGS; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import json | |
import os | |
import pymysql | |
import statistics | |
import time | |
def prepare_values(row): | |
new_row = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
function create_tables() { | |
tbl_1=$(cat <<EOF | |
CREATE TABLE IF NOT EXISTS test_innodb ( | |
user_id CHAR(32) NOT NULL PRIMARY KEY, | |
user_email VARCHAR(254) NOT NULL, | |
created_at DATETIME NOT NULL, | |
tags JSON NOT NULL DEFAULT ('{}'), | |
shared_with JSON NOT NULL DEFAULT ('{}'), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Requirements: | |
# jupyter-notebook: https://jupyter.org/install | |
# Python3: https://www.python.org/downloads | |
# virtualenv: https://pypi.org/project/virtualenv | |
# virtualenvwrapper: https://virtualenvwrapper.readthedocs.io/en/latest/install.html | |
# zsh | |
# Tested with Jupyter Notebook 6.5.3, Python 3.11.4, and zsh 5.8 | |
mkjup() { | |
# This is a base64-encoded skeleton of an .ipynb file, with two variables which are filled via envsubst later |
NewerOlder