sql-query-optimizer | SQL query optimizer that executes an SQL query plan | SQL Database library
kandi X-RAY | sql-query-optimizer Summary
kandi X-RAY | sql-query-optimizer Summary
sql-query-optimizer is a Python library typically used in Database, SQL Database applications. sql-query-optimizer has no bugs, it has no vulnerabilities, it has a Permissive License and it has low support. However sql-query-optimizer build file is not available. You can download it from GitHub.
An SQL query optimizer that executes an SQL query plan and visualizes its performance, made for a project for NTU's CZ4031 (Database System Principles) course. Queries are tested against TPC-H, a benchmark for generating dummy data in a database that attempts to mimic real world operations. The tables present in the database are shown in the image above.
An SQL query optimizer that executes an SQL query plan and visualizes its performance, made for a project for NTU's CZ4031 (Database System Principles) course. Queries are tested against TPC-H, a benchmark for generating dummy data in a database that attempts to mimic real world operations. The tables present in the database are shown in the image above.
Support
Quality
Security
License
Reuse
Support
sql-query-optimizer has a low active ecosystem.
It has 1 star(s) with 1 fork(s). There are 1 watchers for this library.
It had no major release in the last 6 months.
sql-query-optimizer has no issues reported. There are no pull requests.
It has a neutral sentiment in the developer community.
The latest version of sql-query-optimizer is current.
Quality
sql-query-optimizer has 0 bugs and 0 code smells.
Security
sql-query-optimizer has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
sql-query-optimizer code analysis shows 0 unresolved vulnerabilities.
There are 0 security hotspots that need review.
License
sql-query-optimizer is licensed under the MIT License. This license is Permissive.
Permissive licenses have the least restrictions, and you can use them in most projects.
Reuse
sql-query-optimizer releases are not available. You will need to build from source code and install.
sql-query-optimizer has no build file. You will be need to create the build yourself to build the component from source.
Installation instructions, examples and code snippets are available.
It has 1374 lines of code, 30 functions and 25 files.
It has high code complexity. Code complexity directly impacts maintainability of the code.
Top functions reviewed by kandi - BETA
kandi has reviewed sql-query-optimizer and discovered the below as its top functions. This is intended to give you an instant insight into sql-query-optimizer implemented functionality, and help decide if they suit your requirements.
- Get the histogram for a given relation .
- Generate plans for selectivity .
- Gets the plans from the frontend .
- Visualize a plan query .
- Parse a query .
- Creates an explanation string .
- Extract selectivity from a SQL query string .
- Gets the best plan id for the given plan .
- Generate the query string based on selectivity .
- Execute a SQL query .
Get all kandi verified functions for this library.
sql-query-optimizer Key Features
No Key Features are available at this moment for sql-query-optimizer.
sql-query-optimizer Examples and Code Snippets
No Code Snippets are available at this moment for sql-query-optimizer.
Community Discussions
Trending Discussions on sql-query-optimizer
QUESTION
Simplifying a query with a nested query
Asked 2021-Nov-23 at 16:39
I want to remove the need for a nested query if I can from my query below, but I'm struggling to work out how.
This is the schema:
...ANSWER
Answered 2021-Nov-23 at 12:24Give this a try, I believe it gets you what you wanted:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install sql-query-optimizer
First, clone this repository to a local folder on your computer. This repository contains two main folders - the /api backend (server), and the /frontend (client). To ensure that this project runs correctly, we need to set up both the frontend and the backend, then run them concurrently.
Ensure that you have Yarn (A package manager for javascript) and NodeJS installed.
Run yarn install in this root folder.
We are using React as well as a few other dependencies for the frontend.
Ensure that you have Yarn (A package manager for javascript) installed.
cd into /frontend and run yarn install to install the dependencies needed for the client.
We are using Flask to run the web server. We recommend that you use this exact configuration for the PostgreSQL database (aka with a database named "TPC-H").
Ensure that you have Poetry (A package manager for Python) and at minimum Python 3.8 installed. You can run pip install poetry in your environment to install Poetry.
cd into /api and run poetry install to install the Python package dependencies for this backend. We are using Flask as a web server.
By default, the API server starts in production mode. To run in development mode and enable hot reloading, create an .env file in this folder and add the following environment variables:
You will have to connect to a Postgresql database to run the query. This database should be populated with dummy data generated by TPC-H. Continue reading the installation instructions below if you have not generated the TPC-H dataset.
There are two ways to connect to the database. The first way is to input your database details directly in the frontend client itself, but the state will only persist until the page is refreshed. If you do not want to type in your details every time, fill up the .env file with the connection details of your PostgreSQL database. You api/.env file should look something like this now
Other than the above instructions, the following setup instructions below are required if you:. If you've already completed these two steps, feel free to ignore the setup instructions below and simply run yarn start from the root folder in order to start both the frontend and the API server concurrently. Otherwise, do set up the following to ensure that the project runs correctly.
Have not installed PostgreSQL on your computer.
Have not generated a set of TPC-H dummy data and populated a PostgreSQL database with it.
Ensure that you have PostgreSQL installed. This project may work on other database management systems, but has only been tested on PostgreSQL.
Run pgAdmin, which should come bundled in the PostgreSQL installation. If it's your first time accessing it, it will prompt you to create a root user and password - name this user postgres and set the password as postgres. Alternatively, supply your own password, but you will have to change the password in the environment variable of the main application if you do. Create a new database named "TPC-H".
Clone this repository into a new folder.
Open your terminal and run psql -U postgres -f dss.ddl TPC-H from the cloned repository's folder. This command connects you to PostgreSQL as the default user postgres, and runs the SQL commands found in dss.ddl on the database TPC-H. The commands will initialize empty tables in the database similar to the ones shown in the image at the top.
You may generate your own dummy data using TPC-H, or use our pre-generated data, found in this Google drive. Download data.zip and extract it. Each csv file corresponds and contains data of a table in the database.
Navigate back to the pgAdmin interface. Right click each table and click on Import/Export. Import the corresponding csv file into each table, with the format set to csv and encoding set to UTF-8. Set the delimeter to | and click OK to import the data.
Once all data has been imported, right click each table and verify that the data has been correctly imported by clicking View/Edit Data > First 100 Rows.
If all the data seems correct, run psql -U postgres -f dss.ri TPC-H in your terminal. This command will create the constraints on the tables, including initializing the primary keys and foreign keys on the various tables.
Next, right click each table within pgAdmin and click on Maintenance. Tick Vaccuum, and turn Analyze and Verbose Messages on. Run this for each table.
Connection details: TPC-H (Arbitrary name to save this connection for use next time). Machine: localhost (Where your database is running on). Engine: POSTGRES (Which JDBC engine to use to connect to your database). Port: 5432 (Default port to connect to the database). Database: TPC-H (Name of your database). Schema: public (Default schema for the database). User: postgres (Your user that owns the database, default root user is postgres). Password: ******* (Your login password for user postgres).
Download Picasso. Make sure to select the full library (we recommend getting the zip file). Extract it.
Ensure you have at least JDK 6.0 installed. We suggest the latest version of AdoptOpenJDK. If you have your Java environment set up, navigate to ./PicassoRun/Windows/ and run activatedb.bat, compileServer.bat and compileClient.bat in this order to compile the Java files.
To connect to the PostgreSQL database, we will need to update our JDBC driver to the latest version. The JDBC driver serves to connect the Java application to our PostgreSQL database. Download it here.
Navigate to ./Libraries/ and find the jar file for the old JDBC driver for PostgreSQL. It should be named something like PostgreSQL-8.0-311.jdbc3. Replace this file with the latest version that you just downloaded. Rename it so it matches the old name (e.g. PostgreSQL-8.0-311.jdbc3) exactly, so that Picasso can detect it. Alternatively, you can let Picasso detect the name of the new file by modifying the runServer.bat script to include the new jdbc driver in ./PicassoRun/Windows/.
Navigate back to ./PicassoRun/Windows/. We can now start the program. Run runServer.bat to start the Picasso server, then run runClient.bat to run the Picasso client. A GUI should pop up. Click on Enter, and enter the connection details (localhost and port 4444 by default).
The Picasso client GUI should appear. We need to create a new connection to our TPC-H database. In the top menu, click on DBConnection, then click New. The DB Connection Settings window should pop up.
Fill in the following details:
Connection details: TPC-H (Arbitrary name to save this connection for use next time)
Machine: localhost (Where your database is running on)
Engine: POSTGRES (Which JDBC engine to use to connect to your database)
Port: 5432 (Default port to connect to the database)
Database: TPC-H (Name of your database)
Schema: public (Default schema for the database)
User: postgres (Your user that owns the database, default root user is postgres)
Password: ******* (Your login password for user postgres) Click on Save.
Now that we've created our connection profile, go to the orange Settings pane. Choose your new connection under DBConnection Descriptor:. For example, if you've named the connection you just created TPC-H, select that. Picasso then attempts to connect to the database, and prints STATUS: DONE at the bottom if it suceeds. If the server terminal window outputs errors about 'Authentication type 10 not supported', go back to step 12 to update your JDBC driver.
We also have to update our Java3D driver in order for Picasso to be able to show graphs on a 64-bit architecture (it's legacy software). Download the latest Java3D executable from this link. We recommend the java3d-1_5_1-windows-amd64.exe for 64-bit Windows.
Run the executable and install it. Go to the install location (default C:/Program Files/Java/Java3D/1.5.1/) and go to ./lib/ext/. Copy all the jar files there, and paste it into your libraries folder of Piccasso at picasso/Libraries/. Replace any existing files.
Next, go back to the install location of Java3D and go to ./bin/. Copy the j3dcore-ogl.dll file, and paste it in C:/Windows/, replacing any file there. This basically updates your Java3D runtime to 64-bit architecture.
Finally, we can go back to Picasso and load in some query plans in the form of SQL queries to analyze. Ensure that you are connected to your database in the Settings tab (DBConnection Descriptor -> TPC-H).
Click on the QueryTemplate tab just below the Settings section, and click the Load QueryTemplate button on the right. It brings up a default folder. Navigate to the postgres folder, and select any query to start.
As Picasso loads the query in, you will see the SQL query displayed in the textbox. You can name this query for later retrieval by giving it a name in the QueryTemplate Descriptor field.
With your SQL query loaded, click on the Plan Diag tab to generate a diagram enumerating all the optimized plans. If a prompt appears, click on Generate Exact Diagram. Click OK. You should see a colorful 2D square, which is the plan diagram - a collection of the optimal plans generated by the DBMS as the selectivity of your chosen predicates vary.
Read the Picasso documentation for more information on how to use Picasso.
Ensure that you have Yarn (A package manager for javascript) and NodeJS installed.
Run yarn install in this root folder.
We are using React as well as a few other dependencies for the frontend.
Ensure that you have Yarn (A package manager for javascript) installed.
cd into /frontend and run yarn install to install the dependencies needed for the client.
We are using Flask to run the web server. We recommend that you use this exact configuration for the PostgreSQL database (aka with a database named "TPC-H").
Ensure that you have Poetry (A package manager for Python) and at minimum Python 3.8 installed. You can run pip install poetry in your environment to install Poetry.
cd into /api and run poetry install to install the Python package dependencies for this backend. We are using Flask as a web server.
By default, the API server starts in production mode. To run in development mode and enable hot reloading, create an .env file in this folder and add the following environment variables:
You will have to connect to a Postgresql database to run the query. This database should be populated with dummy data generated by TPC-H. Continue reading the installation instructions below if you have not generated the TPC-H dataset.
There are two ways to connect to the database. The first way is to input your database details directly in the frontend client itself, but the state will only persist until the page is refreshed. If you do not want to type in your details every time, fill up the .env file with the connection details of your PostgreSQL database. You api/.env file should look something like this now
Other than the above instructions, the following setup instructions below are required if you:. If you've already completed these two steps, feel free to ignore the setup instructions below and simply run yarn start from the root folder in order to start both the frontend and the API server concurrently. Otherwise, do set up the following to ensure that the project runs correctly.
Have not installed PostgreSQL on your computer.
Have not generated a set of TPC-H dummy data and populated a PostgreSQL database with it.
Ensure that you have PostgreSQL installed. This project may work on other database management systems, but has only been tested on PostgreSQL.
Run pgAdmin, which should come bundled in the PostgreSQL installation. If it's your first time accessing it, it will prompt you to create a root user and password - name this user postgres and set the password as postgres. Alternatively, supply your own password, but you will have to change the password in the environment variable of the main application if you do. Create a new database named "TPC-H".
Clone this repository into a new folder.
Open your terminal and run psql -U postgres -f dss.ddl TPC-H from the cloned repository's folder. This command connects you to PostgreSQL as the default user postgres, and runs the SQL commands found in dss.ddl on the database TPC-H. The commands will initialize empty tables in the database similar to the ones shown in the image at the top.
You may generate your own dummy data using TPC-H, or use our pre-generated data, found in this Google drive. Download data.zip and extract it. Each csv file corresponds and contains data of a table in the database.
Navigate back to the pgAdmin interface. Right click each table and click on Import/Export. Import the corresponding csv file into each table, with the format set to csv and encoding set to UTF-8. Set the delimeter to | and click OK to import the data.
Once all data has been imported, right click each table and verify that the data has been correctly imported by clicking View/Edit Data > First 100 Rows.
If all the data seems correct, run psql -U postgres -f dss.ri TPC-H in your terminal. This command will create the constraints on the tables, including initializing the primary keys and foreign keys on the various tables.
Next, right click each table within pgAdmin and click on Maintenance. Tick Vaccuum, and turn Analyze and Verbose Messages on. Run this for each table.
Connection details: TPC-H (Arbitrary name to save this connection for use next time). Machine: localhost (Where your database is running on). Engine: POSTGRES (Which JDBC engine to use to connect to your database). Port: 5432 (Default port to connect to the database). Database: TPC-H (Name of your database). Schema: public (Default schema for the database). User: postgres (Your user that owns the database, default root user is postgres). Password: ******* (Your login password for user postgres).
Download Picasso. Make sure to select the full library (we recommend getting the zip file). Extract it.
Ensure you have at least JDK 6.0 installed. We suggest the latest version of AdoptOpenJDK. If you have your Java environment set up, navigate to ./PicassoRun/Windows/ and run activatedb.bat, compileServer.bat and compileClient.bat in this order to compile the Java files.
To connect to the PostgreSQL database, we will need to update our JDBC driver to the latest version. The JDBC driver serves to connect the Java application to our PostgreSQL database. Download it here.
Navigate to ./Libraries/ and find the jar file for the old JDBC driver for PostgreSQL. It should be named something like PostgreSQL-8.0-311.jdbc3. Replace this file with the latest version that you just downloaded. Rename it so it matches the old name (e.g. PostgreSQL-8.0-311.jdbc3) exactly, so that Picasso can detect it. Alternatively, you can let Picasso detect the name of the new file by modifying the runServer.bat script to include the new jdbc driver in ./PicassoRun/Windows/.
Navigate back to ./PicassoRun/Windows/. We can now start the program. Run runServer.bat to start the Picasso server, then run runClient.bat to run the Picasso client. A GUI should pop up. Click on Enter, and enter the connection details (localhost and port 4444 by default).
The Picasso client GUI should appear. We need to create a new connection to our TPC-H database. In the top menu, click on DBConnection, then click New. The DB Connection Settings window should pop up.
Fill in the following details:
Connection details: TPC-H (Arbitrary name to save this connection for use next time)
Machine: localhost (Where your database is running on)
Engine: POSTGRES (Which JDBC engine to use to connect to your database)
Port: 5432 (Default port to connect to the database)
Database: TPC-H (Name of your database)
Schema: public (Default schema for the database)
User: postgres (Your user that owns the database, default root user is postgres)
Password: ******* (Your login password for user postgres) Click on Save.
Now that we've created our connection profile, go to the orange Settings pane. Choose your new connection under DBConnection Descriptor:. For example, if you've named the connection you just created TPC-H, select that. Picasso then attempts to connect to the database, and prints STATUS: DONE at the bottom if it suceeds. If the server terminal window outputs errors about 'Authentication type 10 not supported', go back to step 12 to update your JDBC driver.
We also have to update our Java3D driver in order for Picasso to be able to show graphs on a 64-bit architecture (it's legacy software). Download the latest Java3D executable from this link. We recommend the java3d-1_5_1-windows-amd64.exe for 64-bit Windows.
Run the executable and install it. Go to the install location (default C:/Program Files/Java/Java3D/1.5.1/) and go to ./lib/ext/. Copy all the jar files there, and paste it into your libraries folder of Piccasso at picasso/Libraries/. Replace any existing files.
Next, go back to the install location of Java3D and go to ./bin/. Copy the j3dcore-ogl.dll file, and paste it in C:/Windows/, replacing any file there. This basically updates your Java3D runtime to 64-bit architecture.
Finally, we can go back to Picasso and load in some query plans in the form of SQL queries to analyze. Ensure that you are connected to your database in the Settings tab (DBConnection Descriptor -> TPC-H).
Click on the QueryTemplate tab just below the Settings section, and click the Load QueryTemplate button on the right. It brings up a default folder. Navigate to the postgres folder, and select any query to start.
As Picasso loads the query in, you will see the SQL query displayed in the textbox. You can name this query for later retrieval by giving it a name in the QueryTemplate Descriptor field.
With your SQL query loaded, click on the Plan Diag tab to generate a diagram enumerating all the optimized plans. If a prompt appears, click on Generate Exact Diagram. Click OK. You should see a colorful 2D square, which is the plan diagram - a collection of the optimal plans generated by the DBMS as the selectivity of your chosen predicates vary.
Read the Picasso documentation for more information on how to use Picasso.
Support
For any new features, suggestions and bugs create an issue on GitHub.
If you have any questions check and ask questions on community page Stack Overflow .
Find more information at:
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page