JSqlParser icon indicating copy to clipboard operation
JSqlParser copied to clipboard

Get fingerprint from a sql?

Open roseduan opened this issue 3 years ago • 3 comments

How to get the fingerprint from a specified sql? Is there any implemention in JSqlParser?

roseduan avatar Jan 24 '22 04:01 roseduan

Greetings,

there is no specific implementation (because it is not really our concern), however you can safely create a distinct fingerprint by:

  1. parsing your SQL with JSQLParser
  2. de-parsing it (in order to mangle white space and Upper-/Lower-Case spelling)
  3. hashing it with your favorite algorithm (e. g. SHA-1)

manticore-projects avatar Jan 24 '22 08:01 manticore-projects

First you need to specify what you mean by fingerprint. @manticore-projects suggestion is right, if all of your SQL is relevant. But you could also replace concrete values by a e.g. question mark and then

select * from mytable where id = 5

would by equal to

select * from mytable where id = 6

wumpz avatar Feb 06 '22 21:02 wumpz

@wumpz is right of course: For the purpose of execution plans, when Deparsing, you could rewrite all Values (String, Date, Double) with Parameters, before you hash.

manticore-projects avatar Feb 06 '22 23:02 manticore-projects

@roseduan Excuse me, have you solved the problem of obtaining fingerprints?

jacky2026 avatar Nov 04 '22 06:11 jacky2026

Closed, since no further question has been asked.

manticore-projects avatar Nov 12 '22 06:11 manticore-projects