小编Bog*_*mac的帖子

为什么此查询不使用 NLSSORT 索引?

在我们的应用程序中,我们在会话级别配置了不区分大小写的语义:

alter session set NLS_COMP=LINGUISTIC;
alter session set NLS_SORT=BINARY_AI;
Run Code Online (Sandbox Code Playgroud)

但后来我想要一个带有具有二进制语义的 NAME 列的表,因此我相应地定义了一个基于函数的索引:

create table RAW_SCREEN (
   ID   number(10)     constraint RSCR_PK primary key,
   NAME nvarchar2(256) not null
);
create unique index RSCR_IDX on RAW_SCREEN (nlssort(NAME, 'NLS_SORT=BINARY'));
Run Code Online (Sandbox Code Playgroud)

我希望下面的查询能够利用基于函数的索引:

select * from RAW_SCREEN where 
    nlssort(NAME, 'NLS_SORT=BINARY') = nlssort(N'raw_screen1', 'NLS_SORT=BINARY');
Run Code Online (Sandbox Code Playgroud)

但事实并非如此。查询计划显示表扫描。在实验过程中,我发现 NAME 上的简单索引可以解决问题:

create unique index RSCR_IDX2 on RAW_SCREEN (NAME);
Run Code Online (Sandbox Code Playgroud)

再次运行查询时,RSCR_IDX2索引已成功使用。

现在,这并不奇怪,但我不明白为什么优化器没有使用第一个基于函数的索引。索引表达式与 WHERE 条件中使用的表达式完全匹配。您知道为什么没有使用它吗?

注意:这是在 Oracle 10.2 上运行的

如果您想尝试一下,这里有一个完整的测试脚本:

alter session set NLS_COMP=LINGUISTIC;
alter session set NLS_SORT=BINARY_AI;

create table RAW_SCREEN (
   ID                   number(10)            constraint …
Run Code Online (Sandbox Code Playgroud)

oracle

5
推荐指数
1
解决办法
4051
查看次数


如何从源脚本退出powershell?

考虑“outer.ps1”:

"in outer.ps1"
. .\inner.ps1
"in outer.ps1 after sourcing inner.ps1"
Run Code Online (Sandbox Code Playgroud)

来源“inner.ps1”,它刚刚退出:

exit 0
Run Code Online (Sandbox Code Playgroud)

当我运行“outer.ps1”时,输出表明出口只从“inner.ps1”返回:

in outer.ps1
in outer.ps1 after sourcing inner.ps1
Run Code Online (Sandbox Code Playgroud)

是否可以从inner.ps1退出powershell进程?我不想抛出异常,这将是一个正常的终止。

powershell powershell-2.0

4
推荐指数
1
解决办法
809
查看次数

替换文件中第一次出现的字符串

在PowerShell脚本中,为了替换文件中第一次出现的字符串,我提供了下面的代码,该代码会在变量中跟踪是否进行了替换.

这样做有更优雅(惯用)的方式吗?

$original_file = 'pom.xml'
$destination_file =  'pom.xml.new'

$done = $false
(Get-Content $original_file) | Foreach-Object {
    $done
    if ($done) {
        $_
    } else {
        $result = $_ -replace '<version>6.1.26.p1</version>', '<version>6.1.26.p1-SNAPSHOT</version>'
        if ($result -ne $_) {
            $done = $true
        }
        $result
    }
} | Set-Content $destination_file
Run Code Online (Sandbox Code Playgroud)

powershell

3
推荐指数
1
解决办法
5686
查看次数

StatelessSession是否支持延迟加载?

考虑来自"Java Persistence with Hibernate"的数据模型,其中a Bid具有惰性关联Item:

@ManyToOne(optional = false, fetch = FetchType.LAZY) // NOT NULL
@JoinColumn(name = "ITEM_ID") // Actually the default name
protected Item item;
Run Code Online (Sandbox Code Playgroud)

然后下面的代码片段试图Bid通过a 加载StatelessSession然后访问关联的Item:

        Bid bid = (Bid) statelessSession.get(Bid.class, bidId);
        assertNotNull(bid.getItem());
        assertEquals(bid.getItem().getName(), "Bike");
Run Code Online (Sandbox Code Playgroud)

LazyInitializationException即使会话仍处于活动状态,这也会抛出一个.我们可以从这里推断延迟加载不支持StatelessSession吗?

org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session is disconnected
    at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:154)
    at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:266)
    at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:68)
    at org.jpwh.model.simple.Item_$$_jvst6d3_0.getName(Item_$$_jvst6d3_0.java)
    at org.jpwh.test.stateless.CrudWithAssociations.lambda$fetchLazyAssociationForStackOverflow$6(CrudWithAssociations.java:94)
    at org.jpwh.test.stateless.CrudWithAssociations$$Lambda$2/310350177.call(Unknown Source)
    at org.jpwh.env.StatelessSessionTest.transaction(StatelessSessionTest.java:21)
    at org.jpwh.test.stateless.CrudWithAssociations.fetchLazyAssociationForStackOverflow(CrudWithAssociations.java:90)
Run Code Online (Sandbox Code Playgroud)

笔记:

  • 如果我将关联更改为,则代码可以正常工作 …

java hibernate

2
推荐指数
1
解决办法
1210
查看次数