question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why query `system.jdbc.columns` so slow.

See original GitHub issue

env

  • presto 0.210
  • jdk1.8
  • dbeaver 5.2.4
  • DataGrip 2018.2.4

dbeaver

When query from a ‘new’ table - hasn’t been queried in current connection - say select * from t_sales_bill or select bill_id from t_sales_bill it will automatically run the sql below to query all columns in t_sales_bill table AND SO SLOW(cost 36s)!! It happen whenever you query from a ‘new’ table and so wasting time!

SELECT TABLE_CAT, TABLE_SCHEM, TABLE_NAME, COLUMN_NAME, DATA_TYPE,
  TYPE_NAME, COLUMN_SIZE, BUFFER_LENGTH, DECIMAL_DIGITS, NUM_PREC_RADIX,
  NULLABLE, REMARKS, COLUMN_DEF, SQL_DATA_TYPE, SQL_DATETIME_SUB,
  CHAR_OCTET_LENGTH, ORDINAL_POSITION, IS_NULLABLE,
  SCOPE_CATALOG, SCOPE_SCHEMA, SCOPE_TABLE,
  SOURCE_DATA_TYPE, IS_AUTOINCREMENT, IS_GENERATEDCOLUMN
FROM system.jdbc.columns
WHERE TABLE_CAT = 'platform_data' AND TABLE_SCHEM LIKE 'platform_data' ESCAPE '\' AND TABLE_NAME LIKE 't_sales_bill' ESCAPE '\' AND COLUMN_NAME LIKE '%' ESCAPE '\'
ORDER BY TABLE_CAT, TABLE_SCHEM, TABLE_NAME, ORDINAL_POSITION

dbeaver-single-table

DataGrip

DataGrip has the same problem like dbeaver but not so bad but BAD.

DataGrip will query the whole metadata in system.jdbc when connection started. snipaste20181108_223350

datagrip-init

So, it’s like ‘once for all’ not when you need it. BUT it took 55s to query system.jdbc.columns!

SO

  • Why query system.jdbc.columns so slow?
  • Any better database tools for presto?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kokosingcommented, Nov 8, 2018

It looks like your query is slow because dbeaver has a bug. This is very typical bug.

Please take a look at the query:

SELECT TABLE_CAT, TABLE_SCHEM, TABLE_NAME, COLUMN_NAME, DATA_TYPE,
  TYPE_NAME, COLUMN_SIZE, BUFFER_LENGTH, DECIMAL_DIGITS, NUM_PREC_RADIX,
  NULLABLE, REMARKS, COLUMN_DEF, SQL_DATA_TYPE, SQL_DATETIME_SUB,
  CHAR_OCTET_LENGTH, ORDINAL_POSITION, IS_NULLABLE,
  SCOPE_CATALOG, SCOPE_SCHEMA, SCOPE_TABLE,
  SOURCE_DATA_TYPE, IS_AUTOINCREMENT, IS_GENERATEDCOLUMN
FROM system.jdbc.columns
WHERE TABLE_CAT = 'platform_data' AND TABLE_SCHEM LIKE 'platform_data' ESCAPE '\' AND TABLE_NAME LIKE 't_sales_bill' ESCAPE '\' AND COLUMN_NAME LIKE '%' ESCAPE '\'
ORDER BY TABLE_CAT, TABLE_SCHEM, TABLE_NAME, ORDINAL_POSITION

And specifically predicates: TABLE_SCHEM LIKE 'platform_data' ESCAPE '\' and TABLE_NAME LIKE 't_sales_bill' ESCAPE '\'. Notice that your object names contains _, in pattern for LIKE operator _ means any character and in your case it should be escaped. These predicates should look like: TABLE_SCHEM LIKE 'platform\_data' ESCAPE '\' and TABLE_NAME LIKE 't\_sales\_bill' ESCAPE '\'.

Can you please rerun your query but with properly escaped LIKE patterns literals? That would be:

SELECT TABLE_CAT, TABLE_SCHEM, TABLE_NAME, COLUMN_NAME, DATA_TYPE,
  TYPE_NAME, COLUMN_SIZE, BUFFER_LENGTH, DECIMAL_DIGITS, NUM_PREC_RADIX,
  NULLABLE, REMARKS, COLUMN_DEF, SQL_DATA_TYPE, SQL_DATETIME_SUB,
  CHAR_OCTET_LENGTH, ORDINAL_POSITION, IS_NULLABLE,
  SCOPE_CATALOG, SCOPE_SCHEMA, SCOPE_TABLE,
  SOURCE_DATA_TYPE, IS_AUTOINCREMENT, IS_GENERATEDCOLUMN
FROM system.jdbc.columns
WHERE TABLE_CAT = 'platform\_data' AND TABLE_SCHEM LIKE 'platform\_data' ESCAPE '\' AND TABLE_NAME LIKE 't\_sales\_bill' ESCAPE '\' AND COLUMN_NAME LIKE '%' ESCAPE '\'
ORDER BY TABLE_CAT, TABLE_SCHEM, TABLE_NAME, ORDINAL_POSITION
0reactions
findepicommented, Nov 9, 2018

Let me close this in favor of https://github.com/dbeaver/dbeaver/issues/4587

Read more comments on GitHub >

github_iconTop Results From Across the Web

Extremely slow JDBC query - java - Stack Overflow
I have a JDBC query that runs 8-20x slower than the same query in Python (using cx_Oracle). I would expect some normal %...
Read more >
sql server - Query is slow with JDBC parameters, fast with ...
I discovered that if I take out the use of JDBC parameters and just concatenate the values into the SQL string, it runs...
Read more >
Using Presto Jdbc driver results with bad queries while ...
Using Presto Jdbc driver results with bad queries while refreshing schema ... What is the expected result? ... FROM system.jdbc.columns
Read more >
Performance tips for the native JDBC driver - IBM
Avoiding SELECT * SQL queries​​ Even if your application never uses a particular column, the JDBC driver has to be made aware of...
Read more >
JDBC Driver Application Performance Optimization Tutorial
Because database metadata methods that generate ResultSet objects are slow compared to other JDBC methods, their frequent use can impair system performance. The ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found