Configuring PostgreSQL Databases

Ubuntu).
2. Create a new database by running the following command in your terminal: CREATE DATABASE my_database;
3. Connect to your newly created database using psql, which will open up a new terminal window where you can enter SQL commands and interact with your data. Run psql -d my_database.
4. Create a table called “customers” by running the following command: CREATE TABLE customers ( id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, email VARCHAR(100), phone VARCHAR(20), address TEXT );
5. Insert data into your new table using INSERT statements like this one: INSERT INTO customers (name, email, phone) VALUES (‘John Doe’, ‘[email protected]’, ‘123-4567’);
6. Retrieve data from your database using SQL queries with the SELECT statement. For example, to retrieve all rows in the “customers” table, run this command: SELECT * FROM customers;

To hint a query and force specific join methods or access decisions, you can use Leading() and NestLoop(), HashJoin(), MergeJoin() hints along with opening parentheses. For full hinting between n tables, you need to have n-1 nested pairs in Leading(). And each pair is a (). That’s a lot of parentheses! By the way, do you know that the first implementation of POSTGRES had some code in LISP?
Back to our hints, once the Leading() is defined with all those n-1 nested pairs, there is one join method to define for each pair (NestLoop(), HashJoin() or MergeJoin). The one at position i (from 1 to n-1) will have i+1 arguments.
In addition to that, to fully define the execution plan, the access for each of n tables must be one of the scan method, like SeqScan(), IndexScan(), IndexOnlyScan() or BitmapScan(). For example:

/*+
Leading( ( c (b a) ) )
NestLoop(b a) NestLoop(b a c)
SeqScan(b) IndexScan(a table_a_pkey) SeqScan(c)
*/

This hint specifies that the query should join tables b, a and c using nested loops. The first pair (c, b a) is defined in Leading() with two nested pairs: (c, b) and (b a). This means that table c will be joined to table b using a NestLoop join method, which involves reading both tables sequentially. Then, the result of this join will be joined to table a using another NestLoop join method. The scan methods specified in SeqScan() indicate that full scans should be performed on tables b and c.

In YugabyteDB, which uses a storage based on PostgreSQL tuples rather than pages, you don’t see BitmapScan().
For n tables, you will have in total 2*n hints. And you can also count the opening parentheses, which equals the closing ones, and should find 6*n-2 of them for full hinting.

SICORPS