我将 Oracle API for MongoDB 与自治数据库结合使用。 一些查询/聚合管道的性能没有达到我的预期。 如何提高性能?
这种情况下的性能问题通常是由于缺少索引造成的。 诊断这些问题的最佳方法是使用 Oracle SQL 监控。 在幕后,Oracle API for MongoDB 将所有 MongoDB 命令转换为 SQL 操作。 您可以指定MongoDB命令的提示来生成底层SQL的监控报告。 此示例假设您使用 mongosh 连接到数据库。
来自 SQL 管理用户:
grant select on "V$SQL" to your_user;
grant select on "V$SQL_MONITOR" to your_user;
grant advisor to your_user;
grant execute on dbms_sql_monitor to your_user;
mongosh> db.movie.aggregate([{$match : {year:2000}}], {hint :{$native : "MONITOR"}});
或
mongosh> db.movie.find({$match : {year : 2000}}).hint({$native : "MONITOR"});
以下查询可用于确定您刚刚执行的命令的 SQL_ID。
mongosh> db.aggregate([{$sql:`
select sql_fulltext, sql_id
from v$sql
where sql_text like '%MONITOR%' and
sql_text not like '%v$sql%'
order by last_active_time desc
fetch first 1 rows only
`}]);
[
{
SQL_FULLTEXT: '...',
SQL_ID: '6xy9y446n1ha6'
}
]
mongosh> var html =
db.aggregate([{$sql:`
select dbms_sql_monitor.report_sql_monitor(
sql_id => '6xy9y446n1ha6',
report_level => 'ALL',
type => 'ACTIVE'
) as "html"
from dual
`}]).toArray()[0].html;
mongosh> require('fs').writeFileSync('/Users/jspiegel/out.html', html);
在网络浏览器中打开
/Users/jspiegel/out.html
。
报告显示详细信息包括: