xo / usql

Universal command-line interface for SQL databases
MIT License
8.81k stars 346 forks source link

paste multi-line sql is a bit slow? #445

Closed l1t1 closed 4 months ago

l1t1 commented 4 months ago

I use windterm to ssh a linux host and run usql on that host, I found when I paste a sql as following

SELECT
aaa.nspname ,
aaa.relname ,
aaa.table_comment ,
ccc.attname 
FROM
 (
  SELECT   aa.oid,
    obj_description (aa.oid) AS table_comment,
    aa.relname,
    bb.localoid,
    bb.attrnums,
    regexp_split_to_table (
     array_to_string (bb.attrnums, ','),
     ','  
  ) att,
    dd.nspname   FROM   pg_class aa 
  LEFT
 JOIN gp_distribution_policy bb ON bb.localoid = aa.oid 
LEFT
 JOIN pg_namespace dd ON dd.oid = aa.relnamespace 
LEFT
 JOIN pg_inherits hh ON aa.oid = hh.inhrelid  
WHERE   dd.nspname = 'dim'  
AND hh.inhrelid IS NULL 
 ) aaa
LEFT JOIN pg_attribute ccc ON ccc.attrelid = aaa.oid
AND ccc.attnum = aaa.att
WHERE
ccc.attnum > 0
ORDER BY
aaa.relname;

it took about 1 second or two to display all lines on the screen, I think that not a problem of windterm as other CLI such as duckdb 0.10 displayed the pasted sql immediately.

kenshaw commented 4 months ago

@1t1 this is a known issue in general with usql -- if you really need/want the performance, you can turn off syntax highlighting. Due to the way that it's currently implemented, it's N^2 algorithm depending on the length of the string that's being copy/pasted.

$ usql
Type "help" for help.

(not connected)=> \set 
SYNTAX_HL = 'true'
(not connected)=> \set SYNTAX_HL false

I have been meaning to fix/change this, but it would require an immense amount of coding, roughly equal to the effort of usql itself.

l1t1 commented 4 months ago

thank you, \set SYNTAX_HL false works nicely.