One SQL had been running for more than three hours without finishing, while several other queries on the same gbase cluster were suddenly far slower than usual. This is the investigation behind that incident on an 862 build of GBase 8a, the analytical database from Chinese vendor GBASE — and the root cause turned out to be a single parameter changed for an unrelated business need.

The Symptom

The site reported one query still running after 3+ hours, with multiple other queries on the cluster taking far longer than normal. The cluster was on build 862, preparing for an upgrade to 953. Because of the incident, the customer asked for a root-cause analysis and whether 953 would behave the same way.

Investigation

1. Check the SQL running on the cluster

The longest-running query had been going for 12,000 seconds (over 3 hours), followed by another at 10,000+ seconds. The SQL looked like a user repeatedly executing the same statement. It started at 20:14:05.

select COORDINATOR_NAME, ID, user, host, command, start_time, time, state, substring(info,0,100) info from information_schema.COORDINATORS_TASK_INFORMATION where command='query' and time >=0 order by time desc limit 10; 

2. Check the SQL on the compute nodes

Execution time on the compute nodes was also 12,000 seconds, matching the coordinator layer. More importantly, every SQL was on node3 — a strong hint that this one node was the source of the problem.

select NODE_NAME, ID, user, host, command, start_time, time, state, substring(info,0,100) info from information_schema.GNODES_TASK_INFORMATION where command='query' and info is not null and info not like '%information_schema.processlist%' order by time desc limit 10; 

3. Rule out environment and OS-level problems

  • Log into node3 and check for hardware/environment errors: dmesg | grep -i error — nothing.
  • Check the OS logs: tail /var/log/messages — normal, no hardware or OS errors.
  • Check memory: free -g — plenty available, no SWAP in use.

4. Check for sustained resource saturation

iostat -xdc 1 

The disk was continuously at 100% utilization, writing roughly 900 MB/s — an enormous, sustained write load. The customer's OS monitoring history showed disk usage jumping after 20:00 and staying high, which lines up exactly with when the SQL started.

5. Check the database temp directory

du -sh DATABASE_INSTALL_DIR/gnode/tmpdata/* 

Thousands of temporary SRT sort files, totaling 10 TB+.

Drilling Into the Business SQL

Identify the query

A simple TOPN query: an order by with limit 1000, no outer group by, and three subqueries joined with left join inside.

select xxxx from ( ... )a left join ( ... )b on ... left join ( ... )c on order by xxx limit 1000 

Confirm the row counts of the three joined tables

Using create table tmp_a as select ..., a temp table was built for each subquery:

  • First subquery: group by on the main table, 2 billion rows down to 200,000 rows
  • Second subquery: distinct on a dimension table, 2,000 rows
  • Third subquery: a 2-table left join with group by, 20,000 rows

Confirm the final result set, step by step

Strip the unused projection columns and count directly:

select count(*) from a left join b on ... select count(*) from a left join b on ... left join c on ... 

The first left join produced 200,000 rows in under 10 seconds; the second still produced 200,000 rows, also under 10 seconds — no Cartesian product. So a large result set was not the cause. Why, then, would sorting 200,000 rows with a limit generate that much SRT intermediate data?

Find the projection column that breaks performance

Restoring the original SQL column by column from count(*) eventually isolated one column from temporary table C. Its structure showed longtext.

Back in the original SQL, that column was computed with group_concat(xxx) — turning rows into a single string. Yet max(length(xxx)) showed the source values were at most 10 characters long. Why was the intermediate table typed as longtext?

Check the database parameter

show variables like '%group_concat_max_len%' 

It returned 1 MB, not the default 32 KB. Root cause located.

Analysis

Where the parameter came from

group_concat defaults to a 32 KB result (about 10,922 characters in utf8); exceeding it raises Aggregation function group_concat overflow. To solve that, the database added group_concat_max_len as the maximum allowed length for the function — and the user had set it to 1 MB.

Why the column became longtext

When a result is written straight into a temporary intermediate table — as in create table tmpXXX as select — the column width must be estimated in advance, before the table is built, not after the query finishes. At 1 MB, the estimate exceeds the maximum 32 KB allowed for varchar, so the column is typed as longtext.

Why sorting filled the disk

Before sorting, the projection columns involved must be materialized, which means allocating memory up front to hold the materialized data. Build 862 allocates that memory based on the table definition: a longtext can be up to 64 MB, which will never fit, so the data spills to temporary files on disk.

200,000 rows × at least 64 MB each = 12.2 TB — hence the 10 TB+ of temp files on disk. Even at 1 GB/s, writing that takes 3.4 hours.

Why only node3 had the huge temp files

The main table's SQL used group by clttime, cell_id. cell_id is a cell identifier with relatively many distinct values; clttime is a collection date, effectively a single value for the whole day. Because the table was randomly distributed with no hash column, group by picked the first column as the distribution key — so all the data landed on one node.

  • Option A: put cell_id first in the group by to avoid this.
  • Option B: use all group by columns together as the hash distribution key, though that costs performance. The parameter is _t_gcluster_hash_redistribute_groupby_on_multiple_expression.

Can the parameter simply be changed?

It was raised because another workload genuinely produced group_concat results beyond 32 KB, but that same value makes other SQL behave abnormally. A global parameter has exactly one value, and no single value can fit every scenario perfectly.

Solutions

Option 1: Rewrite the SQL (adopted on site)

Constrain the estimated width of the group_concat result, for example by wrapping it in substr:

substr(group_concat(xxx),0,1000) 

The result can no longer exceed 1,000 characters, so the intermediate column becomes varchar(1000). The site adopted this option and the query finished in under 30 seconds.

Option 2: Use a hint

gbase supports session-level parameter overrides through hints:

select /*+group_concat_max_len(3000)*/ ... 

This tells the optimizer that this SQL's group_concat result will not exceed 3,000 bytes — roughly 1,000 utf8 characters.

Option 3: Upgrade to build 95

In build 95, memory is no longer allocated by the column's maximum width. It starts with a block sized to the current data and grows it only when needed, which reduces actual memory usage and brings intermediate result sizes much closer to real disk usage.

Going forward, the lesson is clear: raising one parameter inflated the database's memory estimate, which spilled massive sort files to disk, saturated that node's I/O for hours, and dragged down otherwise healthy queries along with it. A single global value in gbase cannot fit every workload — for important business SQL, setting a per-statement value with a hint is usually safer than changing the global setting.