Core Concepts

💡 Core Concepts

Let's dive deep into the internals of AI Query to figure out why it's so fast, efficient and down right cool. 😎

The Engine

AI Query is so fast and efficient because it's built on an optimized set of libraries, which enables us to perform intelligent optimization known as The Engine. Here's how it works:

Query-level caching

In the AI Query engine, all your queries are natively 'remembered'. When any new queries related to existing queries are identified, the AI Query engine will remember what they were called with, and what they returned. It'll then save it in an in-memory cache.

The cache

The AI Query engine currently stores its cache in memory. This means the cache will last as long as you are logged in - which works well for a developer. When you run a query or setup a database, you’ll start a cache with the AI Query engine. When you logout the cache gets cleared.

In the future, we're planning to persist this cache - either to the filesystem, or to a remote cache. This will mean that AI Query could remember work done across logins and machines.

How does it help?

This approach makes AI Query extremely fast at optimizing and executing workloads. This optimization for executing queries and handling query results means you will always receive responses snappily to requests.

In the future, a persistent cache will open the door to much faster response times. By remembering work done across logins and machines, query responses would be snappy - potentially leading to enormous time savings.

The Database

AI Query requires that the database be setup before any SQL queries can be generated. This allows for the database schema to be readily available to help optimize and execute query requests. This separation further shields AI Query from being directly connected to your database servers for security purposes.

You can setup and manage a database by navigating to Databases. Here you can import a database schema or define / edit / delete tables for a database.

The Query Playground

The aptly named Playground is where users can use AI to generate SQL queries in relation to the selected database. The selected database is a vital context for the AI Query engine during SQL query generation. A history of all query prompts and generated SQL queries are stored against each database.

When a new query prompt is initiated, the Query Type is required to further assist the AI Query engine to generate an accurate SQL query.

You would provide the Query Type for the Query Prompt as follows:

  • Create Query: Generate a SQL query based on a query prompt
  • Optimize Query: Provide a SQL query to have it optimized
  • Suggest Indexes: Provide a SQL query to have table indexes defined in relation to the SQL query

The Explanation Zone

If you ever have to write and/or explain SQL, this is the place to be. Here you can simply copy/paste existing SQL (yes, anything) and have the AI Query engine explain it to you step by step. This is truly a fun place to learn.