【问题标题】:SQLPS tab completion is very slowSQLPS 选项卡完成非常慢
【发布时间】:2013-06-16 02:53:22
【问题描述】:

SQLPS 制表符扩展(制表符补全)太慢了,完全无法使用。我的配置有问题吗?我应该以某种方式升级到更高版本吗?是否有某种修复方法可以使其可用?

相关版本信息:

  • Windows7 64 位
  • SQL Server 2008
  • SQL Server Management Studio 10.0.5512.0
  • SQLPS.exe 文件版本 (10.0.1600.22 ((SQL_PreRelease).080709-1414 )
  • sqlps,$ps 版本表:
    • CLR版本:2.0.50727.5466
    • BuildVersion:6.1.7601.17514
    • PS版本:2.0

【问题讨论】:

    标签: sql-server powershell sqlps


    【解决方案1】:

    据我所知,性能问题实际上在于 SqlServer psprovider 中 Resolve-Path 的实现。 Resolve-Path 是 TabExpansion(在 Powershell v2 中)的默认实现如何完成路径完成。

    我能够通过重写 TabExpansion 函数以使用 Get-ChildItem 和 Where-Object 而不是 Resolve-Path 来解决此问题。你可以find the latest implementation in this bitbucket repo

    这是当前的实现:

    function TabExpansion($line, $lastWord) {
      if (!((get-location).Provider.Name -eq "SqlServer")) {
        TabExpansionSqlPsBackup $line $lastWord
      }
      else {
        $index = $lastWord.LastIndexOfAny(@('\', '/'))
        if ($index -gt -1) { 
          $parent = $lastWord.substring(0, $index+1) 
          $leaf = $lastWord.substring($index+1)
        }
        else {
          $parent = ""
          $leaf = $lastWord
        }
    
        $matches = ls -path $parent | ?{ $_.PSChildName -match "^$leaf" }
        if ($matches) { 
          $matches | %{ $parent + $_.PSChildName } 
        } 
        else {$lastWord}
      }
    }
    

    将该函数放入位于 ~\Documents\WindowsPowerShell\Microsoft.SqlServer.Management.PowerShell.sqlps_profile.ps1 的 sqlps 配置文件中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-17
      • 2011-01-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多