Using the statement editor¶
The statement editor is a web-based client for use with SQream DB. It can be used to run statements, and manage roles and permissions.
We recommend using Google Chrome or Chrome-based browsers to access the statement editor.
In this topic:
- Setting up and starting the statement editor
- Logging in
- Familiarizing yourself with the editor
- DDL optimizer
The statement editor is included with all dockerized installations of SQream DB.
You can start the editor using sqream-console:
$ ./sqream-console sqream-console> sqream editor --start access sqream statement editor through Chrome http://192.168.0.100:3000
When starting the editor, it listens on the local machine, on port 3000.
Open a browser to the host, on port 3000. If the machine is
18.104.22.168, navigate to http://192.168.0.100:3000 .
Fill in your login details for SQream DB. These are the same credentials you might use when using sqream sql or JDBC.
- If using a load balancer, select the
Server pickerbox and make sure to use the correct port (usually
3108). If connecting directly to a worker, make sure to untick the box and use the correct port, usually
- If this is your first time using SQream DB, use database name
- When using SQream DB on AWS, the initial password is the EC2 instance ID.
The editor is built up of main panes.
- Toolbar - used to select the active database you want to work on, limit the number of rows, save query results, control tab behavior, and more.
- Statement area - The statement area is a multi-tab text editor where you write SQL statements. Each tab can connect to a different database.
- Results - Results from a query will populate here.
- Database tree - contains a heirarchy tree of databases, views, tables, and columns. Can be used to navigate and perform some table operations.
See more about each pane below:
In the toolbar, you can perform the folllowing operations (from left to right):
Toggle Database Tree - Click ••• to show or hide the Database Tree pane.
Database dropdown - Select the database you want to the statements to run on.
⯈ RUN / ◼ STOP - Use the ⯈ RUN button to execute the statement in the Editor pane. When a statement is running, the button changes to ◼ STOP, and can be used to stop the active statement.
SQL - Reformats and reindents the statement
Max. Rows - By default, the editor will only fetch the first 1000 rows. Click the number to edit. Click outside the number area to save. Setting a higher limit can slow down your browser if the result set is very large.
💾 (Save) - Save the query text to a file.
📃 (Load) - Load query text from a file.
⋮ (more) -
- Append new results - When checked, every statement executed will open a new Results tab. If unchecked, the Results tab is reused and overwritten with every new statement.
The multi-tabbed statement area is where you write queries and statements.
Select the database you wish to use in the toolbar, and then write and execute statements.
- A new tab can be opened for each statement. Tabs can be used to separate statements to different databases.
- Multiple statements can be written in the same tab, separated by semicolons.
- When multiple statements exist in the tab, clicking Run executes all statements in the tab, or only the selected statements.
If this is your first time with SQream DB, see our first steps guide.
The results pane shows query results and execution information. By default, only the first 1000 results are returned (modify via the Toolbar).
A context menu, accessible via a right click on the results tab, enables:
- Renaming the tab name
- Show the SQL query text
- Reload results
- Close the current tab
- Close all result tabs
During query execution the time elapsed is tracked in seconds.
The SHOW STATISTICS button opens the query’s execution plan, for monitoring purposes.
The database tree shows the database objects (e.g. tables, columns, views), as well as some metadata like row counts.
It also contains a few predefined catalog queries for execution.
Each level contains a context menu relevant to that object, accessible via a right-click.
- Show row count in the database tree
- Copy the create table script to the clipboard
- Copy SELECT to clipboard
- Copy INSERT to clipboard
- Copy DELETE to clipboard
- Rename table - Copy RENAME TABLE to clipboard
- Create table LIKE - Copy CREATE TABLE AS to clipboard
- Add column - Copy ADD COLUMN to clipboard
- Truncate table - Copy TRUNCATE to clipboard
- Drop table - Copy DROP TABLE to pclipboard
- Create a table - Add a new table by running a statement, or alternatively use the Add new link near the TABLES group.
Creating a new table is also possible using the wizard which can guide you with creating a table.
Refer to the CREATE TABLE reference for information about creating a table (e.g. able parameters like default values, identity, etc.).
Fill in the table name, and add a new row for each table column.
If a table by the same name exists, check Create or Replace table to overwrite it.
Click EXEC to create the table.
To see catalog views, click the catalog view name in the tree. The editor will run a query on that view.
Desktop notificaitons lets you receive a notification when a statement is completed.
You can minimize the browser or switch to other tabs, and still recieve a notification when the query is done.
Enable the desktop notification through the Allow Desktop Notification from the menu options.
The DDL optimizer tab analyzes database tables and recommends possible optimizations, per the Optimization and best practices guide.
Navigate to the DDL optimizer module by selecting it from the ⋮ (“More”) menu.
Table- select the database and desired table to optimize
Rowsis the number to scan for analysis. Defaults to 1,000,000
Buffer Size- overhead threshold to use when analyzing
VARCHARfields. Defaults to 10%.
Optimize NULLs- attempt to figure out field nullability.
EXECUTE to start the optimization process.
The analysis process shows results for each row.
The results are displayed in two tabs:
OPTIMIZED COLUMNS - review the system recommendation to:
- decrease the length of
- remove the
- decrease the length of
OPTIMIZED DDL - The recommended CREATE TABLE statement
Analyzing the DDL culminates in four possible actions:
- COPY DDL TO CLIPBOARD - Copies the optimized CREATE TABLE to the clipboard
- CREATE A NEW TABLE - Creates the new table structure with
_newappended to the table name. No data is populated
- CREATE AND INSERT INTO EXISTING DATA - Create a new table in same database and schema as the original table and populates the data
- Back - go back to the statement editor and abandon any recommendations