DEV Community

mmllllzcn
mmllllzcn

Posted on

GBase Database Connection Modes Compared: Interactive, Pipe, Script, and Remote Execution

There are four common ways to execute SQL through dbaccess: interactive mode, pipe mode, script mode, and remote execution.

Which one is faster?

The answer depends on what you measure. Client startup, SQL input handling, terminal initialization, and network communication all contribute to execution time.

This article presents a reproducible benchmarking method for comparing the four connection modes in GBase Database (GBase 8s), without assuming that one mode is always faster than another.

1. Four Ways to Execute SQL with dbaccess

Let's start with four commands that execute the same query:

1. Interactive mode

dbaccess - -
Enter fullscreen mode Exit fullscreen mode

Enter the SQL statement after the interactive prompt appears.

2. Pipe mode

echo "select count(*) from systables;" | dbaccess gbase8s
Enter fullscreen mode Exit fullscreen mode

SQL is passed to dbaccess through standard input.

3. Script mode

dbaccess gbase8s /data/script/check.sql
Enter fullscreen mode Exit fullscreen mode

The SQL statement is stored in a file and executed directly by dbaccess.

4. Remote execution

dbaccess gbase8s@gbaseserver /data/script/check.sql
Enter fullscreen mode Exit fullscreen mode

The client connects to a remote database server using the connection information configured for gbaseserver.

All four methods can execute the same SQL statement, but their execution paths are not identical.

2. How to Measure Execution Time

For a meaningful comparison, use the real value reported by the Linux time command.

For example, measure pipe mode:

time (echo "select count(*) from systables;" | dbaccess gbase8s)
Enter fullscreen mode Exit fullscreen mode

Follow three basic rules:

  • Run each test at least three times.
  • Use the median instead of relying on a single result.
  • Establish a new connection for every run.

The third rule is particularly important.

Reusing an existing interactive session measures SQL execution inside an established connection. It does not measure the full cost of starting a new client and connecting to the database.

For GBase Database (GBase 8s), client startup can include reading environment variables, parsing sqlhosts, initializing the client, and establishing the database connection.

These costs should be considered separately from SQL execution time.

3. Where Does the Overhead Come From?

The following table summarizes the main execution stages:

Execution stage Interactive Pipe Script Remote
Client startup Yes Yes Yes Yes
Interactive interface initialization Yes No No No
SQL input from file No No Yes Yes
Network communication Yes, when remote Yes, when remote Yes, when remote Yes

One important distinction: remote communication is not exclusive to the remote execution mode. Interactive, pipe, and script modes can also connect to remote database instances when their connection settings specify a remote server.

The actual differences are:

  • Interactive mode: May include menu or terminal initialization overhead.
  • Pipe mode: Reads SQL from standard input without requiring a SQL file.
  • Script mode: Reads SQL statements from a file.
  • Remote execution: Depends on network conditions and communication with the remote database server.

For short queries, client startup and connection establishment can account for a significant proportion of the total time.

For longer queries, SQL execution and data transfer become more important.

4. Why Pipe Mode Is Not Always the Fastest

Pipe mode can appear faster in simple tests because it avoids interactive interface initialization and does not require reading a SQL file.

However, this does not mean it always delivers the highest throughput.

Consider a query that returns a large result set:

echo "select * from t_big;" | dbaccess gbase8s > /dev/null
Enter fullscreen mode Exit fullscreen mode

The client still has to retrieve and process the result set. Output handling can become a significant part of the total execution time.

To isolate output-related overhead, compare two runs:

# Write output to a file
time (echo "select * from t_big;" | dbaccess gbase8s > /tmp/result.txt)

# Discard output
time (echo "select * from t_big;" | dbaccess gbase8s > /dev/null)
Enter fullscreen mode Exit fullscreen mode

The difference helps reveal the cost of writing output to a file.

For a fair comparison, keep the query, database state, client settings, and network conditions consistent.

The key distinction is between two different measurements:

  • Connection overhead: How long does it take to start the client, connect, and execute a small query?
  • Data throughput: How efficiently can the client retrieve and handle a large result set?

These metrics should not be mixed into a single performance conclusion.

5. Batch Execution Changes the Comparison

A single SQL statement makes connection overhead relatively important.

But what happens when a script contains 100 SQL statements?

In that case, the initial connection cost is distributed across many statements, making the total SQL execution time more significant.

For example:

dbaccess -e gbase8s /data/script/check_all.sql
Enter fullscreen mode Exit fullscreen mode

The -e option echoes SQL statements along with their execution information, helping operators inspect individual statement execution times.

This is useful when troubleshooting batch jobs or identifying slow statements.

GBase Database script execution processes statements sequentially in this execution model. It is not automatically parallelized simply because multiple SQL statements are included in one file.

If parallel execution is required, it needs to be designed separately, taking transaction dependencies and database workload into account.

6. How to Report Benchmark Results Correctly

Avoid conclusions such as:

"Script mode is N times slower than pipe mode."

That statement may only be true under one specific test environment.

A more useful conclusion describes the conditions:

"Under this data volume, terminal configuration, and network environment, script mode adds SQL file input overhead compared with pipe mode. The difference is noticeable for short queries but becomes less significant when executing a larger batch."

A reproducible benchmark should document:

  • GBase Database version
  • Operating system and hardware
  • Local or remote connection
  • SQL statement and result-set size
  • Terminal configuration
  • Number of test runs
  • Median execution time
  • Output destination

This allows other engineers to understand the result and repeat the experiment.

Conclusion

GBase Database (GBase 8s) provides several ways to execute SQL through dbaccess, each suited to a different operational requirement.

  • Interactive mode is useful for manual investigation and immediate feedback.
  • Pipe mode is convenient for one-off SQL execution and shell automation.
  • Script mode is suitable for repeatable SQL jobs and batch operations.
  • Remote execution supports database administration across machines.

There is no universally fastest execution mode. The result depends on whether you are measuring client startup, connection establishment, SQL execution, or result-set handling.

Choose the execution mode according to the task first. Then measure its overhead under your actual workload.

Top comments (0)