Skip to content

Commit

Permalink
修复pgsql数据库下执行计划查看 (#2638)
Browse files Browse the repository at this point in the history
* 修复pgsql数据库下执行计划查看

* linter format

* pgsql:还原query_check,不检查disable_star

* pgsql query_check: add explain test

* python format
  • Loading branch information
peixubin authored May 14, 2024
1 parent f81fb45 commit 14fbd5e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions sql/engines/pgsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ def query_check(self, db_name=None, sql=""):
except IndexError:
result["bad_query"] = True
result["msg"] = "没有有效的SQL语句"
if re.match(r"^select", sql, re.I) is None:
if re.match(r"^select|^explain", sql, re.I) is None:
result["bad_query"] = True
result["msg"] = "不支持的查询语法类型!"
if "*" in sql:
result["has_star"] = True
result["msg"] = "SQL语句中含有 * "
result["msg"] += "SQL语句中含有 * "
return result

def query(
Expand Down
14 changes: 14 additions & 0 deletions sql/engines/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,20 @@ def test_query_check_star_sql(self):
},
)

def test_query_check_explain(self):
sql = "explain select x from xx "
new_engine = PgSQLEngine(instance=self.ins)
check_result = new_engine.query_check(db_name="archery", sql=sql)
self.assertDictEqual(
check_result,
{
"msg": "",
"bad_query": False,
"filtered_sql": sql.strip(),
"has_star": False,
},
)

def test_filter_sql_with_delimiter(self):
sql = "select * from xx;"
new_engine = PgSQLEngine(instance=self.ins)
Expand Down
2 changes: 1 addition & 1 deletion sql/templates/sqlquery.html
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ <h4 class="modal-title text-danger">收藏语句</h4>
else if (sql === 'show create table') {
sqlContent = "desc " + $("#table_name").val() + ";"
}
} else if (optgroup === "MySQL") {
} else if (optgroup === "MySQL" || optgroup === "PgSQL" ) {
//查看执行计划
if (sql === 'explain') {
sqlContent = 'explain ' + sqlContent
Expand Down

0 comments on commit 14fbd5e

Please sign in to comment.