Skip to main content

Posts

Showing posts with the label SQL

SQL history lesson with Oracle V2

I recently stubmbled upon this website that hosts a publicly available Oracle RDBMS instance running Oracle v2.3.2, which according to this Wikipedia article is the first commercially available version of Oracle. This version is not written in C, but in PDP-11 assembly. The website also has the manuals available. At this time the company was called Relational Software Incorporated or RSI for short, which they later renamed to Oracle Systems Corporation and then to Oracle Corporation. Before this the company was called Software Development Laboratories (SDL). Let’s have a quick look at this and see how it compares with newer versions. This version uses “UFI”, the predecessor of SQL*Plus. Let’s first create a table SQL>CREATE TABLE T1 SQL>ID(NUMBER NONULL UNIQUE IMAGE), SQL>NAME(CHAR(20) NONULL) SQL>/ Table created. And let’s do the same with Oracle 26ai SQL> CREATE TABLE T1 ( 2 ID NUMBER PRIMARY KEY, 3 NAME CHAR(20) NOT NULL 4 ) 5 / Table created. ...

Tutorial: Add a QRCODE() function to TiDB

The code for this tutorial is available here . Objectives This tutorial demonstrates how easy it is to add a new function to TiDB that can be used in a SQL-statement. We want to add a function for creating QRCodes. TiDB is aiming to be compatible with MySQL . However as the functionality we’re adding doesn’t exist in MySQL this isn’t a real concern. For reference here is the architecture of a TiDB cluster: We’re only going to add the function to TiDB (in red in the above image), which means this can’t be pushed down to TiKV or TiFlash , however for this function that’s fine. The TiDB Development Guide has a page that describes some of this and more. When adding functions to TiDB you should aim for things that can be merged into upstream TiDB instead of running and maintaining your own fork. Might be good to discuss your plans in a GitHub issue before actually starting to do any work. Step 1: Adding the function to the parser For this open parser/ast/functions.go and add th...

When simple SQL can be complex

I think SQL is a very simple language, but ofcourse I'm biased. But even a simple statement might have more complexity to it than you might think. Do you know what the result is of this statement? SELECT FALSE = FALSE = TRUE; scroll down for the answer. The answer is: it depends. You might expect it to return false because the 3 items in the comparison are not equal. But that's not the case. In PostgreSQL this is the result: postgres=# SELECT FALSE = FALSE = TRUE; ?column? ---------- t (1 row) So it compares FALSE against FALSE, which results in TRUE and then That is compared against TRUE, which results in TRUE. PostgreSQL has proper boolean literals . Next up is MySQL: mysql> SELECT FALSE = FALSE = TRUE; +----------------------+ | FALSE = FALSE = TRUE | +----------------------+ | 1 | +----------------------+ 1 row in set (0.00 sec) This is similar but it's slightly different. The result is 1 because in My...

Unittesting your indexes

During FOSDEM PGDay I watched the "Indexes: The neglected performance all-rounder" talk by Markus Winand. Both his talk and the "SQL Performance Explained" book (which is also available online ) are great. The conclusion of the talk is that we should put more effort in carefully designing indexes. But how can we make sure the indexes are really used now and in the future? We need to write some tests for it. So I wrote a small Python script to test index usage per query. This uses the JSON explain format available in MySQL 5.6. It's just a proof-of-concept so don't expect too much of it yet (but please sent pull requests!). A short example: #!/usr/bin/python3 import indextest class tester(indextest.IndexTester): def __init__(self): dbparams = { 'user': 'msandbox', 'password': 'msandbox', 'host': 'localhost', 'port': ...

Books vs. e-Books for DBA's

As most people still do I learned to read using books. WhooHoo! Books are nice. Besides reading them they are also a nice decoration on your shelf. There is a brilliant TED talk by Chip Kidd on this subject. But sometimes books have drawbacks. This is where I have to start the comparison with vinyl records (Yes, you're still reading a database oriented blog). Vinyl records look nice and are still being sold and yes I also still use them. The drawback is that car dealers start to look puzzeled if you ask them if your new multimedia system in your car is able to play your old Led Zeppelin records. The market for portable record players is small, and that's for a good reason. The problem with books about databases is that they get old very soon. The MySQL 5.1 Cluster Certification Study Guide was printed by lulu.com which made it possible to quickly update the material. This made sure that the material wasn't outdated when you bought it. I like to use books as refere...