Skip to content

Commit

Permalink
Merge pull request #1253 from weideguo/master
Browse files Browse the repository at this point in the history
mongodb查询优化 (#1252)
  • Loading branch information
hhyo authored Dec 1, 2021
2 parents e776988 + f115b03 commit b1d48cf
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions sql/engines/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,11 +688,13 @@ def filter_sql(self, sql='', limit_num=0):
def query_check(self, db_name=None, sql=''):
"""提交查询前的检查"""

sql = sql.strip()
if sql.startswith("explain"):
sql = sql.replace("explain", "") + ".explain()"
sql = sql[7:]+".explain()"
sql = re.sub("[;\s]*.explain\(\)$", ".explain()", sql).strip()
result = {'msg': '', 'bad_query': False, 'filtered_sql': sql, 'has_star': False}
pattern = re.compile(
r'''^db\.(\w+\.?)+(?:\([\s\S]*\)$)|^db\.getCollection\((?:\s*)(?:'|")(\w+\.?)+('|")(\s*)\)\.([A-Za-z]+)(\([\s\S]*\)$)''')
r'''^db\.(\w+\.?)+(?:\([\s\S]*\)(\s*;*)$)|^db\.getCollection\((?:\s*)(?:'|")(\w+\.?)+('|")(\s*)\)\.([A-Za-z]+)(\([\s\S]*\)(\s*;*)$)''')
m = pattern.match(sql)
if m is not None:
logger.debug(sql)
Expand Down

0 comments on commit b1d48cf

Please sign in to comment.