From 4b6818eb344a567eb1c5e8d6f3810c6ce480430b Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 4 Apr 2024 16:02:31 +1100 Subject: [PATCH] Sudoku for HUMG Hanoi 2024 --- README.md | 2 +- binder/Dockerfile | 2 +- ...ASIA Summit 2021 - NEW (MariaDB) SQL.ipynb | 1977 +++++++++++++++++ binder/mariadb_config.json | 7 +- binder/sudoku.ipynb | 592 +++++ 5 files changed, 2575 insertions(+), 5 deletions(-) create mode 100644 binder/FOSSASIA Summit 2021 - NEW (MariaDB) SQL.ipynb create mode 100644 binder/sudoku.ipynb diff --git a/README.md b/README.md index 98f600f..ac37d50 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MariaDB Jupyter Kernel -[![badge](https://img.shields.io/badge/Try%20MariaDB-@%20binder-579ACA.svg?logo=data:image/png;base64,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)](https://mybinder.org/v2/gh/MariaDB/mariadb_kernel.git/master?urlpath=lab/tree/binder/try_it_out.ipynb) +[![badge](https://img.shields.io/badge/Try%20MariaDB-@%20binder-579ACA.svg?logo=data:image/png;base64,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)](https://mybinder.org/v2/gh/MariaDB/mariadb_kernel.git/master?urlpath=lab/tree/binder-humg-hanoi-2024/sudoku.ipynb) ![GitHub](https://github.com/MariaDB/mariadb_kernel/workflows/CI/badge.svg) ![badge](https://img.shields.io/badge/version-v0.2.0-yellow) diff --git a/binder/Dockerfile b/binder/Dockerfile index 363e327..5959259 100644 --- a/binder/Dockerfile +++ b/binder/Dockerfile @@ -1,4 +1,4 @@ -FROM jupyter/scipy-notebook:lab-3.1.4 +FROM jupyter/scipy-notebook:latest USER root diff --git a/binder/FOSSASIA Summit 2021 - NEW (MariaDB) SQL.ipynb b/binder/FOSSASIA Summit 2021 - NEW (MariaDB) SQL.ipynb new file mode 100644 index 0000000..c05d53d --- /dev/null +++ b/binder/FOSSASIA Summit 2021 - NEW (MariaDB) SQL.ipynb @@ -0,0 +1,1977 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# **FOSSASIA Summit 2021**\n", + "# NEW (MariaDB) SQL\n", + "## Practical Examples of Modern SQL to solve harder problems" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Code Examples:\n", + "\n", + "* [CTEs](https://dbfiddle.uk/?rdbms=mariadb_10.3&fiddle=3ca4c4f811ac12f2d0e8b3b6c11799a8)\n", + "* [Recursive CTEs](https://dbfiddle.uk/?rdbms=mariadb_10.3&fiddle=939a43cfcd7396b1ad00c7d8cda867dc)\n", + "* [Recursive CTEs CYCLES RESTRICT](https://dbfiddle.uk/?rdbms=mariadb_10.5&fiddle=84813c2f2eb4f76938c50fe9f58ea586)\n", + "* [INSERT RETURNING](https://dbfiddle.uk/?rdbms=mariadb_10.5&fiddle=d44138556fbe1872e06fe6cb36dbeda8)\n", + "* [System Versioned Tables - time](https://dbfiddle.uk/?rdbms=mariadb_10.3&fiddle=42260ada361656a76b59d4999f559247)\n", + "* [System Versioned Tables - transaction](https://dbfiddle.uk/?rdbms=mariadb_10.3&fiddle=35435ec490bcbd351a6dfd91e8964f57)\n", + "* [System Versioned Tables - partitioning](https://dbfiddle.uk/?rdbms=mariadb_10.5&fiddle=e6658a5663747ebbc71113a2e0f7103c)\n", + "* [IPv6 - INET6 Datatype](https://dbfiddle.uk/?rdbms=mariadb_10.5&fiddle=6cb350bfa716d577e1c1af03a54a2ee5)\n", + "* [Application Time Periods](https://dbfiddle.uk/?rdbms=mariadb_10.4&fiddle=2625f132da5536e748be6b72211c4afd)\n", + "* [Application Time Periods - without Overlaps](https://dbfiddle.uk/?rdbms=mariadb_10.5&fiddle=e7cf6718bec732f3e01505ea25e8cd7d)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## *Common Table Expressions - CTEs - MariaDB 10.2+*" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
version()
10.5.10-MariaDB
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "select version();" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "create database if not exists ctetests;" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "use ctetests;" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "create or replace table student_tests (\n", + " name CHAR(10), test CHAR(10), \n", + " score TINYINT, test_date DATE\n", + ");" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### **Adding some data into the table**" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "INSERT INTO student_tests \n", + " (name, test, score, test_date) VALUES\n", + " ('Chun', 'SQL', 75, '2012-11-05'), \n", + " ('Chun', 'Tuning', 73, '2013-06-14'),\n", + " ('Esben', 'SQL', 43, '2014-02-11'), \n", + " ('Esben', 'Tuning', 31, '2014-02-09'), \n", + " ('Kaolin', 'SQL', 56, '2014-01-01'),\n", + " ('Kaolin', 'Tuning', 88, '2013-12-29'), \n", + " ('Tatiana', 'SQL', 75, '2012-04-28'), \n", + " ('Tatiana', 'Tuning', 83, '2013-09-30');" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### **Running a CTE**" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
nametestscoretest_date
ChunSQL752012-11-05
EsbenSQL432014-02-11
KaolinSQL562014-01-01
TatianaSQL752012-04-28
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "WITH sqltest AS \n", + " ( SELECT *\n", + " FROM student_tests\n", + " WHERE test = 'SQL'\n", + ")\n", + "SELECT *\n", + "FROM sqltest;" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
nametestscoretest_datenametestscoretest_date
ChunSQL752012-11-05TatianaSQL752012-04-28
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "WITH sqltest AS \n", + " ( SELECT *\n", + " FROM student_tests\n", + " WHERE test = 'SQL'\n", + ")\n", + "SELECT *\n", + "FROM sqltest t1\n", + "JOIN sqltest t2 ON t1.score=t2.score\n", + "WHERE t1.name != t2.name\n", + "AND t1.name < t2.name;" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# **Recursive CTEs** (MariaDB-10.2+)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "use ctetests;" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "CREATE OR REPLACE TABLE bus_routes (origin varchar(50), dst varchar(50));" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "INSERT INTO bus_routes VALUES \n", + " ('New York', 'Boston'), \n", + " ('Boston', 'New York'), \n", + " ('New York', 'Washington'), \n", + " ('Washington', 'Boston'), \n", + " ('Washington', 'Raleigh'),\n", + " ('Boston', 'Sydney');" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "set max_recursive_iterations = 20;" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Form of Recursive CTEs \n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "WITH RECURSIVE cte AS (\n", + " SELECT anchor_data -- This deterimines types, field names, and initial data of `cte`\n", + " FROM ....\n", + " UNION [ALL]\n", + " SELECT recursive_part\n", + " FROM .....\n", + ")\n", + "SELECT ... FROM cte;" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Where can I go from New York" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
dst
New York
Boston
Washington
Raleigh
Sydney
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "WITH RECURSIVE bus_dst AS ( \n", + " SELECT origin as dst\n", + " FROM bus_routes\n", + " WHERE origin='New York' \n", + " UNION\n", + " SELECT bus_routes.dst\n", + " FROM bus_routes\n", + " JOIN bus_dst ON bus_dst.dst= bus_routes.origin \n", + ") \n", + "SELECT * FROM bus_dst;" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Watch out for casting" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
col
NULL
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "WITH RECURSIVE tbl AS (\n", + " SELECT NULL AS col\n", + " UNION\n", + " SELECT \"THIS NEVER SHOWS UP\" AS col FROM tbl\n", + ")\n", + "SELECT col FROM tbl;" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
col
NULL
THIS WILL SHOW UP
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "WITH RECURSIVE tbl AS (\n", + " SELECT CAST(NULL AS CHAR(50)) AS col\n", + " UNION SELECT \"THIS WILL SHOW UP\" AS col FROM tbl\n", + ") \n", + "SELECT col FROM tbl;" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Recursive CTEs CYCLE RESTRICT (MariaDB 10.5+)" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "CREATE TABLE t1 (from_ int, to_ int);" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "INSERT INTO t1 VALUES (1,2), (1,100), (2,3), (3,4), (4,1);" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
from_to_
12
1100
23
34
41
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "SELECT * FROM t1;" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
depthdistancefrom_to_
0011
1112
1991100
2223
3334
4641
5712
51051100
6823
7934
81241
91312
91111100
101423
111534
121841
131912
131171100
142023
152134
162441
172512
171231100
182623
192734
203041
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "WITH RECURSIVE cte (depth, distance, from_, to_) AS ( \n", + " SELECT 0,0,1,1\n", + " UNION DISTINCT\n", + " SELECT depth+1, distance + abs(t1.from_ - t1.to_), t1.from_, t1.to_ \n", + " FROM t1\n", + " JOIN cte ON t1.from_ = cte.to_ \n", + ") \n", + "SELECT * FROM cte;" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
depthdistancefrom_to_
0011
1112
1991100
2223
3334
4641
5712
51051100
6823
7934
81241
91312
91111100
101423
111534
121841
131912
131171100
142023
152134
162441
172512
171231100
182623
192734
203041
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "WITH RECURSIVE cte (depth, distance, from_, to_) AS ( \n", + " SELECT 0,0,1,1\n", + " UNION DISTINCT\n", + " SELECT depth+1, distance + abs(t1.from_ - t1.to_), t1.from_, t1.to_ \n", + " FROM t1\n", + " JOIN cte ON t1.from_ = cte.to_ \n", + ")\n", + "SELECT * FROM cte;" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
depthdistancefrom_to_
0011
1112
1991100
2223
3334
4641
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "WITH RECURSIVE cte (depth, distance, from_, to_) AS ( \n", + " SELECT 0,0,1,1\n", + " UNION DISTINCT\n", + " SELECT depth+1, distance + abs(t1.from_ - t1.to_), t1.from_, t1.to_ \n", + " FROM t1\n", + " JOIN cte ON t1.from_ = cte.to_ \n", + ")\n", + "CYCLE from_, to_ RESTRICT\n", + "SELECT * FROM cte;" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Insert RETURNING (MariaDB 10.5+)\n", + "`RELACE ... RETURNING` (MariaDB 10.5+)\n", + "`DELETE ... RETURNING` (MariaDB 10.3+)" + ] + }, + { + "cell_type": "code", + "execution_count": 101, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "ERROR 1007 (HY000): Can't create database 'ins'; database exists\n" + ] + } + ], + "source": [ + "create database ins;" + ] + }, + { + "cell_type": "code", + "execution_count": 133, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "use ins;" + ] + }, + { + "cell_type": "code", + "execution_count": 134, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "create or replace table users (\n", + "id int unsigned not null auto_increment primary key,\n", + "name varchar(30));" + ] + }, + { + "cell_type": "code", + "execution_count": 135, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
id
1
2
3
4
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "insert into users (name) values ('bob'), ('jane'), ('fred'), ('harry')\n", + "returning id;" + ] + }, + { + "cell_type": "code", + "execution_count": 136, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "alter table users add unique key(name);" + ] + }, + { + "cell_type": "code", + "execution_count": 138, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
idname
9john
10sarah
11carmel
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "insert ignore into users (name)\n", + "values ('john'), ('bob'), ('sarah'), ('carmel')\n", + "returning id,name;" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# System Versioned Tables (MariaDB-10.3)" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "create database sv;" + ] + }, + { + "cell_type": "code", + "execution_count": 115, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "use sv;\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "SQL:2011 standard form" + ] + }, + { + "cell_type": "code", + "execution_count": 116, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "CREATE OR REPLACE TABLE t(\n", + " x INT,\n", + " start_timestamp TIMESTAMP(6) GENERATED ALWAYS AS ROW START,\n", + " end_timestamp TIMESTAMP(6) GENERATED ALWAYS AS ROW END,\n", + " PERIOD FOR SYSTEM_TIME(start_timestamp, end_timestamp)\n", + ") WITH SYSTEM VERSIONING;" + ] + }, + { + "cell_type": "code", + "execution_count": 123, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "CREATE OR REPLACE TABLE t (\n", + "x INT\n", + ") WITH SYSTEM VERSIONING;" + ] + }, + { + "cell_type": "code", + "execution_count": 124, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "INSERT INTO t VALUES (1),(3),(5);" + ] + }, + { + "cell_type": "code", + "execution_count": 125, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "INSERT INTO t VALUES (5),(6),(8);" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
x
1
3
5
5
6
8
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "select * from t;" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
xROW_STARTROW_END
12021-03-17 13:21:30.0877182038-01-19 14:14:07.999999
32021-03-17 13:21:30.0877182038-01-19 14:14:07.999999
52021-03-17 13:21:30.0877182038-01-19 14:14:07.999999
52021-03-17 13:21:32.0735612038-01-19 14:14:07.999999
62021-03-17 13:21:32.0735612038-01-19 14:14:07.999999
82021-03-17 13:21:32.0735612038-01-19 14:14:07.999999
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "SELECT x, ROW_START, ROW_END FROM t;" + ] + }, + { + "cell_type": "code", + "execution_count": 126, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "delete from t where x = 5;" + ] + }, + { + "cell_type": "code", + "execution_count": 127, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "insert into t VALUES (15),(26),(48);" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
xROW_STARTROW_END
12021-03-17 13:21:30.0877182038-01-19 14:14:07.999999
32021-03-17 13:21:30.0877182038-01-19 14:14:07.999999
62021-03-17 13:21:32.0735612038-01-19 14:14:07.999999
82021-03-17 13:21:32.0735612038-01-19 14:14:07.999999
152021-03-17 13:21:47.4458822038-01-19 14:14:07.999999
262021-03-17 13:21:47.4458822038-01-19 14:14:07.999999
482021-03-17 13:21:47.4458822038-01-19 14:14:07.999999
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "SELECT x, ROW_START, ROW_END FROM t;" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
xROW_STARTROW_END
12021-03-17 13:21:30.0877182038-01-19 14:14:07.999999
32021-03-17 13:21:30.0877182038-01-19 14:14:07.999999
52021-03-17 13:21:30.0877182021-03-17 13:21:44.563212
52021-03-17 13:21:32.0735612021-03-17 13:21:44.563212
62021-03-17 13:21:32.0735612038-01-19 14:14:07.999999
82021-03-17 13:21:32.0735612038-01-19 14:14:07.999999
152021-03-17 13:21:47.4458822038-01-19 14:14:07.999999
262021-03-17 13:21:47.4458822038-01-19 14:14:07.999999
482021-03-17 13:21:47.4458822038-01-19 14:14:07.999999
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "SELECT x, ROW_START, ROW_END\n", + "FROM t\n", + "FOR SYSTEM_TIME ALL;" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
x
1
3
5
5
6
8
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "SELECT *\n", + "FROM t\n", + "FOR SYSTEM_TIME AS OF TIMESTAMP '2021-03-17 13:21:44';" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
x
1
3
6
8
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "SELECT *\n", + "FROM t\n", + "FOR SYSTEM_TIME FROM '2021-03-17 13:21:45' TO '2021-03-17 13:21:47.445882';" + ] + }, + { + "cell_type": "code", + "execution_count": 118, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "ALTER TABLE t DROP SYSTEM VERSIONING;" + ] + }, + { + "cell_type": "code", + "execution_count": 93, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "ERROR 4124 (HY000): Table `t` is not system-versioned\n" + ] + } + ], + "source": [ + "SELECT * FROM t FOR SYSTEM_TIME AS OF TIMESTAMP '2021-03-17 12:32:33.850974';" + ] + }, + { + "cell_type": "code", + "execution_count": 119, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "Stage: 2 of 2 'Enabling keys' 0% of stage done\r", + " \r" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "ALTER TABLE t ADD COLUMN ts TIMESTAMP(6) GENERATED ALWAYS AS ROW START,\n", + " ADD COLUMN te TIMESTAMP(6) GENERATED ALWAYS AS ROW END,\n", + " ADD PERIOD FOR SYSTEM_TIME(ts, te),\n", + " ADD SYSTEM VERSIONING;" + ] + }, + { + "cell_type": "code", + "execution_count": 130, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
x
1
3
6
8
15
26
48
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "select x from t;" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Transaction Precise History in Innodb" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "CREATE OR REPLACE TABLE tinnodb (\n", + " x INT,\n", + " start_trxid BIGINT UNSIGNED GENERATED ALWAYS AS ROW START,\n", + " end_trxid BIGINT UNSIGNED GENERATED ALWAYS AS ROW END,\n", + " PERIOD FOR SYSTEM_TIME(start_trxid, end_trxid)\n", + ") WITH SYSTEM VERSIONING;" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "insert into tinnodb (x) values (4), (22), (33);" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
xstart_trxidend_trxid
436118446744073709551615
2236118446744073709551615
3336118446744073709551615
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "select * from tinnodb;" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "begin;\n", + "insert into tinnodb (x) values (124), (222), (133);\n", + "insert into tinnodb (x) values (44), (422), (433);\n", + "commit;" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
xstart_trxidend_trxid
436118446744073709551615
2236118446744073709551615
3336118446744073709551615
12436818446744073709551615
22236818446744073709551615
13336818446744073709551615
4436818446744073709551615
42236818446744073709551615
43336818446744073709551615
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "select * from tinnodb;" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
xstart_trxidend_trxid
436118446744073709551615
2236118446744073709551615
3336118446744073709551615
12436818446744073709551615
22236818446744073709551615
13336818446744073709551615
4436818446744073709551615
42236818446744073709551615
43336818446744073709551615
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "select *\n", + "from tinnodb \n", + "FOR SYSTEM_TIME AS OF TRANSACTION 368;\n" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "CREATE OR REPLACE TABLE inv (\n", + " x INT,\n", + " start_trxid BIGINT UNSIGNED GENERATED ALWAYS AS ROW START INVISIBLE,\n", + " end_trxid BIGINT UNSIGNED GENERATED ALWAYS AS ROW END INVISIBLE,\n", + " PERIOD FOR SYSTEM_TIME(start_trxid, end_trxid)\n", + ") WITH SYSTEM VERSIONING;" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "insert into inv select x from tinnodb;" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
x
4
22
33
124
222
133
44
422
433
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "select * from inv;" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
xstart_trxidend_trxid
439318446744073709551615
2239318446744073709551615
3339318446744073709551615
12439318446744073709551615
22239318446744073709551615
13339318446744073709551615
4439318446744073709551615
42239318446744073709551615
43339318446744073709551615
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "select x, start_trxid, end_trxid FROM inv;" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Paritioning Storing history separate" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "Stage: 2 of 2 'Enabling keys' 0% of stage done\r", + " \r" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "alter table t PARTITION BY SYSTEM_TIME (\n", + " PARTITION p_hist HISTORY,\n", + " PARTITION p_cur CURRENT\n", + " );" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Time based only, not Innodb transaction-precise\n", + "\n", + "Must have one `CURRENT` parition" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "CREATE TABLE tvlimt (x INT) WITH SYSTEM VERSIONING\n", + " PARTITION BY SYSTEM_TIME LIMIT 100000 (\n", + " PARTITION p0 HISTORY,\n", + " PARTITION p1 HISTORY,\n", + " PARTITION pcur CURRENT\n", + " );" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " history rows into partition p0, and\n", + " \n", + " when it reaches a size of 100000 rows, MariaDB will switch to partition p1\n", + " \n", + " so when p1 overflows, MariaDB will issue a warning, but will continue writing into it" + ] + }, + { + "cell_type": "code", + "execution_count": 132, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "CREATE OR REPLACE TABLE tinerval (x INT) WITH SYSTEM VERSIONING \n", + " PARTITION BY SYSTEM_TIME \n", + " INTERVAL 1 MONTH \n", + " PARTITIONS 12;" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# INET6 datatype (MariaDB-10.5)" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "create database inet6;" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "use inet6;" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "CREATE TABLE t1 (a INET6);" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "INSERT INTO t1 VALUES ('2001:0db8:0000:0000:0000:ff00:0042:8329');" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "INSERT INTO t1 VALUES ('::ffff:192.0.2.128');\n", + "INSERT INTO t1 VALUES ('::192.0.2.128');" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
a
2001:db8::ff00:42:8329
2001:db8::ff00:42:8329
::ffff:192.0.2.128
::192.0.2.128
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "select * from t1;" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "ERROR 4079 (HY000): Illegal parameter data type inet6 for operation 'decimal_typecast'\n" + ] + } + ], + "source": [ + "SELECT CAST(a AS DECIMAL) FROM t1;" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "create table t2 (a varbinary(16));" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "insert into t2 select * from t1;" + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
hex(a)
20010DB8000000000000FF0000428329
20010DB8000000000000FF0000428329
00000000000000000000FFFFC0000280
000000000000000000000000C0000280
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "select hex(a) from t2;" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
hex(t2.a)a
20010DB8000000000000FF00004283292001:db8::ff00:42:8329
20010DB8000000000000FF00004283292001:db8::ff00:42:8329
20010DB8000000000000FF00004283292001:db8::ff00:42:8329
20010DB8000000000000FF00004283292001:db8::ff00:42:8329
00000000000000000000FFFFC0000280::ffff:192.0.2.128
000000000000000000000000C0000280::192.0.2.128
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "select hex(t2.a), t1.a\n", + "from t1\n", + "join t2 using (a);" + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + " CREATE OR REPLACE TABLE tg (a INET6, b VARCHAR(64));" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "INSERT INTO tg VALUES (NULL,'2001:db8::ff00:42:8328');\n", + "INSERT INTO tg VALUES (NULL,'2001:db8::ff00:42:832a garbage');" + ] + }, + { + "cell_type": "code", + "execution_count": 83, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
COALESCE(a,b)
2001:db8::ff00:42:8328
NULL
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + " SELECT COALESCE(a,b) FROM tg;" + ] + }, + { + "cell_type": "code", + "execution_count": 84, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
LevelCodeMessage
Warning1292Incorrect inet6 value: '2001:db8::ff00:42:832a garbage'
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "show warnings;" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Application Time Periods (MariaDB 10.4+)" + ] + }, + { + "cell_type": "code", + "execution_count": 87, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "create database apptime;" + ] + }, + { + "cell_type": "code", + "execution_count": 88, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "use apptime;" + ] + }, + { + "cell_type": "code", + "execution_count": 89, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "CREATE TABLE t1(\n", + " name VARCHAR(50), \n", + " date_1 DATE,\n", + " date_2 DATE,\n", + " PERIOD FOR date_period(date_1, date_2));" + ] + }, + { + "cell_type": "code", + "execution_count": 90, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "INSERT INTO t1 (name, date_1, date_2) VALUES\n", + " ('a', '1999-01-01', '2000-01-01'),\n", + " ('b', '1999-01-01', '2018-12-12'),\n", + " ('c', '1999-01-01', '2017-01-01'),\n", + " ('d', '2017-01-01', '2019-01-01');" + ] + }, + { + "cell_type": "code", + "execution_count": 91, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
namedate_1date_2
a1999-01-012000-01-01
b1999-01-012018-12-12
c1999-01-012017-01-01
d2017-01-012019-01-01
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "select * from t1;" + ] + }, + { + "cell_type": "code", + "execution_count": 92, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "DELETE FROM t1\n", + "FOR PORTION OF date_period\n", + " FROM '2001-01-01' TO '2018-01-01';" + ] + }, + { + "cell_type": "code", + "execution_count": 93, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
namedate_1date_2
a1999-01-012000-01-01
b1999-01-012001-01-01
c1999-01-012001-01-01
d2018-01-012019-01-01
b2018-01-012018-12-12
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "select * from t1;" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "* a is unchanged, as the range falls entirely out of the specified portion to be deleted.\n", + "* b, with values ranging from 1999 to 2018, is split into two rows, 1999 to 2000 and 2018-01 to 2018-12.\n", + "* c, with values ranging from 1999 to 2017, where only the upper value falls within the portion to be deleted, has been shrunk to 1999 to 2001.\n", + "* d, with values ranging from 2017 to 2019, where only the lower value falls within the portion to be deleted, has been shrunk to 2018 to 2019. " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### constraints\n", + "\n", + "* The FROM...TO clause must be constant\n", + "* Multi-delete is not supported " + ] + }, + { + "cell_type": "code", + "execution_count": 95, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
namedate_1date_2
a1999-01-012000-01-01
b1999-01-012018-12-12
c1999-01-012017-01-01
d2017-01-012019-01-01
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "TRUNCATE t1;\n", + "\n", + "INSERT INTO t1 (name, date_1, date_2) VALUES\n", + " ('a', '1999-01-01', '2000-01-01'),\n", + " ('b', '1999-01-01', '2018-12-12'),\n", + " ('c', '1999-01-01', '2017-01-01'),\n", + " ('d', '2017-01-01', '2019-01-01');\n", + "\n", + "SELECT * FROM t1;" + ] + }, + { + "cell_type": "code", + "execution_count": 97, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "UPDATE t1 FOR PORTION OF date_period\n", + " FROM '2000-01-01' TO '2018-01-01' \n", + "SET name = CONCAT(name,'_original');" + ] + }, + { + "cell_type": "code", + "execution_count": 98, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
namedate_1date_2
a1999-01-012000-01-01
b1999-01-012000-01-01
b2018-01-012018-12-12
b_original2000-01-012018-01-01
c1999-01-012000-01-01
c_original2000-01-012017-01-01
d2018-01-012019-01-01
d_original2017-01-012018-01-01
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "\n", + "SELECT * FROM t1 ORDER BY name;" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Application Time Periods - WITHOUT OVERLAPS (MariaDB 10.5+)" + ] + }, + { + "cell_type": "code", + "execution_count": 99, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "CREATE OR REPLACE TABLE rooms (\n", + " room_number INT,\n", + " guest_name VARCHAR(255),\n", + " checkin DATE,\n", + " checkout DATE,\n", + " PERIOD FOR p(checkin,checkout)\n", + " );\n", + " \n", + " INSERT INTO rooms VALUES \n", + " (1, 'Regina', '2020-10-01', '2020-10-03'),\n", + " (2, 'Cochise', '2020-10-02', '2020-10-05'),\n", + " (1, 'Nowell', '2020-10-03', '2020-10-07'),\n", + " (2, 'Eusebius', '2020-10-04', '2020-10-06');" + ] + }, + { + "cell_type": "code", + "execution_count": 100, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "ERROR 1062 (23000): Duplicate entry '2-2020-10-06-2020-10-04' for key 'room_number'\n" + ] + } + ], + "source": [ + "CREATE OR REPLACE TABLE rooms (\n", + " room_number INT,\n", + " guest_name VARCHAR(255),\n", + " checkin DATE,\n", + " checkout DATE,\n", + " PERIOD FOR p(checkin,checkout),\n", + " UNIQUE (room_number, p WITHOUT OVERLAPS)\n", + " );\n", + " \n", + " INSERT INTO rooms VALUES \n", + " (1, 'Regina', '2020-10-01', '2020-10-03'),\n", + " (2, 'Cochise', '2020-10-02', '2020-10-05'),\n", + " (1, 'Nowell', '2020-10-03', '2020-10-07'),\n", + " (2, 'Eusebius', '2020-10-04', '2020-10-06');" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "MariaDB", + "language": "SQL", + "name": "mariadb_kernel" + }, + "language_info": { + "file_extension": ".sql", + "mimetype": "text/plain", + "name": "SQL" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/binder/mariadb_config.json b/binder/mariadb_config.json index 69db5a7..a92ff82 100644 --- a/binder/mariadb_config.json +++ b/binder/mariadb_config.json @@ -3,7 +3,8 @@ "host": "localhost", "password": "", "start_server": "True", - "client_bin": "mysql", - "server_bin": "mysqld", - "db_init_bin": "mysql_install_db" + "client_bin": "mariadb", + "server_bin": "mariadbd", + "db_init_bin": "mariadb-install-db", + "extra_server_config": ["--skip-host-cache", "--skip-name-resolve"] } diff --git a/binder/sudoku.ipynb b/binder/sudoku.ipynb new file mode 100644 index 0000000..c102297 --- /dev/null +++ b/binder/sudoku.ipynb @@ -0,0 +1,592 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "58e790a4-4cee-4c6b-abc4-432868c7fb06", + "metadata": {}, + "source": [] + }, + { + "cell_type": "markdown", + "id": "587fd50b-19fb-44b6-85d7-951a36e0dff0", + "metadata": {}, + "source": [ + "Based on https://www.sqlservercentral.com/articles/solve-sudoku-with-t-sql-part-1-1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8ae2958a-1638-47b7-a5ff-a49906bed69f", + "metadata": {}, + "outputs": [], + "source": [ + "select version()" + ] + }, + { + "cell_type": "markdown", + "id": "d28bc38c-c136-4c8b-83b8-518236b71b68", + "metadata": {}, + "source": [ + "/* 81 long number table of row, column and block mapping */" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "87bcccf1-b3ac-48dc-9162-82bde5817e32", + "metadata": {}, + "outputs": [], + "source": [ + "create table tGrid (CoordinateID int primary key, RowNum int, ColumnNum int, BlockNum int);" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e86aae8b-0770-445e-b8b3-2733d5dd04be", + "metadata": {}, + "outputs": [], + "source": [ + "INSERT INTO tGrid\n", + "SELECT seq+1 AS CoordinateID,\n", + " seq div 9 +1 AS RowNum,\n", + " seq MOD 9 +1 AS ColumnNum,\n", + " (seq div 27)*3 + 1 + ((seq div 3) MOD 3) AS BlockNum\n", + "FROM seq_0_to_80;" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c2f44a5d-ac98-4f2f-b918-00bafeebdb73", + "metadata": {}, + "outputs": [], + "source": [ + "select * from tGrid order by CoordinateID limit 28;" + ] + }, + { + "cell_type": "markdown", + "id": "3b0c00db-4d77-43f8-a36a-de835b88649e", + "metadata": {}, + "source": [ + "Table of what we've already solved" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a7badf2c-1b10-450a-a53c-456b2d5e9454", + "metadata": {}, + "outputs": [], + "source": [ + "CREATE OR REPLACE TABLE tFixed (CoordinateID INT PRIMARY KEY, Value CHAR(1));" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ee1dd2a5-4d80-4a16-ae30-708d2ebbc8b9", + "metadata": {}, + "outputs": [], + "source": [ + "set @PuzzleIn = '023780460000620000060304080001000534280000097439000100010205040000036000056018370'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7153939a-1fa6-4427-a6f3-9b2ccdf5c32d", + "metadata": {}, + "outputs": [], + "source": [ + "INSERT INTO tFixed (CoordinateID, Value)\n", + "SELECT CoordinateID, SUBSTRING(@PuzzleIn, CoordinateID, 1) AS Value\n", + "FROM tGrid\n", + "WHERE SUBSTRING(@PuzzleIn, CoordinateID, 1) != '0';" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9d998e48-0760-43af-84ec-738bed530d75", + "metadata": {}, + "outputs": [], + "source": [ + "CREATE OR REPLACE TABLE tOption (CoordinateID INT, Value INT, Key (CoordinateID));" + ] + }, + { + "cell_type": "markdown", + "id": "6017bb83-2b85-4a0c-8c75-12403d0bd094", + "metadata": {}, + "source": [ + "All possible values" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "072a5325-5e68-4326-8295-36774adb332f", + "metadata": {}, + "outputs": [], + "source": [ + "SELECT CoordinateID, b.seq FROM tGrid AS a CROSS JOIN seq_1_to_9 AS b;" + ] + }, + { + "cell_type": "markdown", + "id": "4cef8f14-3210-40c2-884e-d0829aa7a3f4", + "metadata": {}, + "source": [ + "All possible values, excluding known values that are fixed" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "152177f2-c911-4bbc-8061-5dd114a5db69", + "metadata": {}, + "outputs": [], + "source": [ + "SELECT CoordinateID,\n", + " b.seq\n", + "FROM tGrid AS a\n", + "LEFT JOIN tFixed f USING (CoordinateID)\n", + "CROSS JOIN seq_1_to_9 AS b\n", + "WHERE f.CoordinateID IS NULL;" + ] + }, + { + "cell_type": "markdown", + "id": "bbacd89a-bd80-4521-9119-f4d604e497ba", + "metadata": {}, + "source": [ + "Same query using subquery" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6057cd49-9efb-499f-996f-bb36de3cd0b7", + "metadata": {}, + "outputs": [], + "source": [ + "SELECT CoordinateID,\n", + " b.seq\n", + "FROM tGrid AS a\n", + "CROSS JOIN seq_1_to_9 AS b\n", + "WHERE NOT EXISTS\n", + " (SELECT 1\n", + " FROM tFixed c\n", + " WHERE a.CoordinateID = c.CoordinateID );" + ] + }, + { + "cell_type": "markdown", + "id": "350965b8-89ed-4b0d-9112-973b915da036", + "metadata": {}, + "source": [ + "In addition to exluding the fixed values we know about, exclude same value on the same row" + ] + }, + { + "cell_type": "markdown", + "id": "00b53344-7b9e-4038-a5ed-91336679690b", + "metadata": {}, + "source": [ + "AND NOT EXISTS (\n", + " SELECT 1 FROM tFixed c\n", + " INNER JOIN tGrid d ON c.CoordinateID = d.CoordinateID\n", + " WHERE a.RowNum = d.RowNum AND b.seq = c.Value\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "581efa8a-8d20-4409-801f-7b9ee2842d04", + "metadata": {}, + "source": [ + "And same value on the same column" + ] + }, + { + "cell_type": "markdown", + "id": "8779113a-196a-4d3d-b998-e580a271c00f", + "metadata": {}, + "source": [ + "AND NOT EXISTS (\n", + " SELECT 1 FROM tFixed c\n", + " INNER JOIN tGrid d ON c.CoordinateID = d.CoordinateID\n", + " WHERE a.ColumnNum = d.ColumnNum AND b.seq = c.Value\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "db7eef0c-b27e-4341-820d-8eaf9d9aa2ed", + "metadata": {}, + "source": [ + "And same value in the same grid" + ] + }, + { + "cell_type": "markdown", + "id": "d23b147b-6b4f-4f0d-95e9-663b576a6493", + "metadata": {}, + "source": [ + "AND NOT EXISTS (\n", + " SELECT 1 FROM tFixed c\n", + " INNER JOIN tGrid d ON c.CoordinateID = d.CoordinateID\n", + " WHERE a.BlockNum = d.BlockNum AND b.seq = c.Value\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "103c5010-6155-4ee4-9e9e-275ae68ee82e", + "metadata": {}, + "source": [ + "And to this list of options append the fixed values we had" + ] + }, + { + "cell_type": "markdown", + "id": "889e8b5e-28de-460d-bb71-a5d01eefc834", + "metadata": {}, + "source": [ + "UNION\n", + "SELECT CoordinateID, Value FROM tFixed;" + ] + }, + { + "cell_type": "markdown", + "id": "ddd5b7ce-08c1-41c2-9a5c-6241ee304f49", + "metadata": {}, + "source": [ + "Resulting query" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3c33e449-8c50-46d1-80b7-91948d41668c", + "metadata": {}, + "outputs": [], + "source": [ + "INSERT INTO tOption (CoordinateID, Value)\n", + "SELECT CoordinateID,\n", + " seq\n", + "FROM tGrid AS a\n", + "CROSS JOIN seq_1_to_9 AS b\n", + "WHERE NOT EXISTS\n", + " (SELECT 1\n", + " FROM tFixed c\n", + " WHERE a.CoordinateID = c.CoordinateID )\n", + " AND NOT EXISTS\n", + " (SELECT 1\n", + " FROM tFixed c\n", + " INNER JOIN tGrid d ON c.CoordinateID = d.CoordinateID\n", + " WHERE a.RowNum = d.RowNum\n", + " AND b.seq = c.Value )\n", + " AND NOT EXISTS\n", + " (SELECT 1\n", + " FROM tFixed c\n", + " INNER JOIN tGrid d ON c.CoordinateID = d.CoordinateID\n", + " WHERE a.ColumnNum = d.ColumnNum\n", + " AND b.seq = c.Value )\n", + " AND NOT EXISTS\n", + " (SELECT 1\n", + " FROM tFixed c\n", + " INNER JOIN tGrid d ON c.CoordinateID = d.CoordinateID\n", + " WHERE a.BlockNum = d.BlockNum\n", + " AND b.seq = c.Value )\n", + "UNION\n", + "SELECT CoordinateID,\n", + " Value\n", + "FROM tFixed;" + ] + }, + { + "cell_type": "markdown", + "id": "897119da-c965-4d31-94e3-c9ab7a7724d5", + "metadata": {}, + "source": [ + "Duplicates exist" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "713604b2-0aa3-4387-a003-2d42217a3249", + "metadata": {}, + "outputs": [], + "source": [ + "select * from tOption order by CoordinateID limit 10;" + ] + }, + { + "cell_type": "markdown", + "id": "6eea7e88-846b-49e5-84a4-ceeb0c843445", + "metadata": {}, + "source": [ + "So with 81 Coordinates (9 x 9 grid), cross join them all. Use SQL to generate SQL" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bdfa7207-1c90-4ef9-a305-9fbe0cceb6aa", + "metadata": {}, + "outputs": [], + "source": [ + "SELECT @SelectQuery := GROUP_CONCAT(' (SELECT Value AS `',\n", + " CoordinateID,\n", + " '` FROM tOption WHERE CoordinateID = ',\n", + " CoordinateID,\n", + " ') AS `',\n", + " CoordinateID,\n", + " '`'\n", + " SEPARATOR ' CROSS JOIN ')\n", + "FROM\n", + " (SELECT DISTINCT CoordinateID\n", + " FROM tOption) AS b;" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "68d88531-f7b4-4399-aa9f-5eaf74d58ecb", + "metadata": {}, + "outputs": [], + "source": [ + "SELECT @ExclusionQuery := GROUP_CONCAT('`', l.CoordinateID, '` <> `', r.CoordinateID, '`' SEPARATOR ' AND ')\n", + "FROM tGrid l\n", + "CROSS JOIN tGrid r\n", + "WHERE (l.RowNum = r.RowNum\n", + " OR l.ColumnNum = r.ColumnNum\n", + " OR l.BlockNum = r.BlockNum)\n", + " AND r.CoordinateID > l.CoordinateID;" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "243b6f9b-249c-44ad-a552-cea9652dc5a5", + "metadata": {}, + "outputs": [], + "source": [ + "select @columns := group_concat('`', seq, '`' SEPARATOR ',') from seq_1_to_81;" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "114d72fb-bda3-4298-8737-62c08dff8ec3", + "metadata": {}, + "outputs": [], + "source": [ + "EXECUTE IMMEDIATE concat('SELECT ROW_NUMBER() OVER (ORDER BY `1` ASC) AS SolutionID, ',\n", + " @columns,\n", + " ' FROM ( SELECT * FROM',\n", + " @SelectQuery,\n", + " ' WHERE ',\n", + " @ExclusionQuery,\n", + " ') AS x')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "639cbb2f-6c82-44b1-9423-ccf844296a8d", + "metadata": {}, + "outputs": [], + "source": [ + "SELECT @SelectQuery50 := GROUP_CONCAT(' (SELECT Value AS `', CoordinateID, '` FROM tOption WHERE CoordinateID = ', CoordinateID, ') AS `', CoordinateID, '`' SEPARATOR ' CROSS JOIN ')\n", + "FROM\n", + " (SELECT seq AS CoordinateID\n", + " FROM seq_1_to_50) b;" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "15ce1946-8da6-466d-82b5-571dc51ec74d", + "metadata": {}, + "outputs": [], + "source": [ + "SELECT @ExclusionQuery50 := GROUP_CONCAT('`', l.CoordinateID, '` <> `', r.CoordinateID, '`' SEPARATOR ' AND ')\n", + "FROM tGrid l\n", + "CROSS JOIN tGrid r\n", + "WHERE (l.RowNum = r.RowNum\n", + " OR l.ColumnNum = r.ColumnNum\n", + " OR l.BlockNum = r.BlockNum)\n", + " AND r.CoordinateID > l.CoordinateID\n", + " AND r.CoordinateID <= 50\n", + " AND l.CoordinateID <= 50;" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e455c964-29de-483d-a540-2e33d6035451", + "metadata": {}, + "outputs": [], + "source": [ + "EXECUTE IMMEDIATE concat('create or replace table tOption50( CoordinateID int, key (CoordinateID)) select * FROM ',\n", + " @SelectQuery50,\n", + " ' WHERE ',\n", + " @ExclusionQuery50);" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1fb346b6-667d-4eed-8898-f89f0d6cc908", + "metadata": {}, + "outputs": [], + "source": [ + "SELECT @SelectQuery81 := GROUP_CONCAT(' (SELECT Value AS `', CoordinateID, '` FROM tOption WHERE CoordinateID = ', CoordinateID, ') AS `', CoordinateID, '`' SEPARATOR ' CROSS JOIN ')\n", + "FROM\n", + " (SELECT seq AS CoordinateID\n", + " FROM seq_51_to_81) b;" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e7f1c10e-c2b4-471e-8a76-cd18b95f2559", + "metadata": {}, + "outputs": [], + "source": [ + "EXECUTE IMMEDIATE concat('SELECT ROW_NUMBER() OVER (ORDER BY `1` ASC) AS SolutionID, ',\n", + " @columns,\n", + " ' FROM ( SELECT * FROM tOption50 CROSS JOIN ',\n", + " @SelectQuery81,\n", + " ' WHERE ',\n", + " @ExclusionQuery,\n", + " ') AS x')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0182a68a-fd32-4aac-bc7c-dc5e0f6167fc", + "metadata": {}, + "outputs": [], + "source": [ + "set @PuzzleIn = '023780460000620000060304080001000534280000097439000100010205040000036000056018370'\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "badf9d48-b16a-47eb-96d8-3d6d6f2790e6", + "metadata": {}, + "outputs": [], + "source": [ + "set @PuzzleIn = '600050002010702040000346000084000590509000207032000480000165000020407060300090004'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9b4a53d3-e8b2-495d-a0ce-591ae34f9786", + "metadata": {}, + "outputs": [], + "source": [ + "set @PuzzleIn = '800259004040010070000407000302080506580302091607040302000504000060090020700826009'\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b3f5132c-1d25-43ab-8f8c-3c7e83b3a8e1", + "metadata": {}, + "outputs": [], + "source": [ + "set @PuzzleIn = '703200104054019380000500000070000805060000030308000090000001000035920460407008903'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f6902e6e-97a8-4fb2-a2ac-5f0a2b68f46e", + "metadata": {}, + "outputs": [], + "source": [ + "set @PuzzleIn = '700200008020405070004080300060508037009000800180607020001070600050903010600004003'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e67c1aba-b63e-44cd-849f-6260b638abe9", + "metadata": {}, + "outputs": [], + "source": [ + "set @PuzzleIn = '000400000004063200809000503090030005040658030600010070901000804005840100000007000'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0ece6a76-40f3-4942-a137-d0ebcd7c5f96", + "metadata": {}, + "outputs": [], + "source": [ + "set @PuzzleIn = '007400803000206001000085700026000039004000100370000680908620000000108000630009200'\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3d347850-cbca-41b1-9957-a98671e186ae", + "metadata": {}, + "outputs": [], + "source": [ + "set @PuzzleIn = '019600430000098000002005100098074001020000080700850620007500800000730000056001970'\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f958cb94-7ca4-47e1-a49c-45e4fcee78a3", + "metadata": {}, + "outputs": [], + "source": [ + "set @PuzzleIn = '280060079100007006070930080907000605008000700040000090090025060800600002650010047'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ededf2a5-d4a3-4066-8ba9-21c91cb7b7f0", + "metadata": {}, + "outputs": [], + "source": [ + "set @PuzzleIn = '107608209840050036000000000300106004060000090200305007000000000430060052508209301'" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "MariaDB", + "language": "SQL", + "name": "mariadb_kernel" + }, + "language_info": { + "name": "" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}