-
Notifications
You must be signed in to change notification settings - Fork 404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve sql obfuscation regular expressions #2861
Comments
These may already be solved if we agree that #2714 is an acceptable change. |
I wanted an easier to understand benchmark in order to compare our current implementation with the one I have proposed. I put it up at https://github.com/jsumners-nr/sql-parser-bench. The benchmark runs 10,000 iterations for each parser to parse all of our cross agent SQL parsing tests. This still obscures the finer details of each algorithm, but makes it easier to see the difference. The results are pretty consistently close to:
I want to call out that the replacement parser supports common table expressions (CTEs) whereas our current one does not. If we instead run a 10,000 iteration test of a singular SQL statement that both support: select
foo,
bar,
baz
from some_db.some_table as a_table
where
foo = 'foo' We get a result like:
I think this is more representative of what would be encountered during normal operation. I also think we could improve either algorithm with an LRU cache. |
To be clear: I don't think there is anything we can do to the regular expressions to satisfy the linter rule. The linter rule is keying off "zero or more" and "one or more" operators. Those are necessary for the type of parsing being done by these rules. So we either solidify the exceptions with an explanation, or come up with a different way to do the parsing (which is what I have proposed and benchmarked). |
Doing some more research, I have discovered:
|
node-newrelic/lib/util/sql/obfuscate.js
Lines 10 to 17 in d2fba9d
node-newrelic/lib/db/statement-matcher.js
Lines 8 to 10 in d2fba9d
These regular expressions are triggering sonar-js's "slow regex" rule. We need to investigate what the regular expressions do, and see if we can improve them.
The text was updated successfully, but these errors were encountered: