加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl – DBIx :: Class示例

发布时间:2020-12-15 21:45:27 所属栏目:大数据 来源:网络整理
导读:在下面的示例中: my $rs = $schema-resultset('CD')-search({ 'artist.name' = 'Bob Marley' 'liner_notes.notes' = { 'like','%some text%' },},{ join = [qw/ artist liner_notes /],order_by = [qw/ artist.name /],}); DBIx cookbook说这是将生成的sql
在下面的示例中:
my $rs = $schema->resultset('CD')->search(
{
  'artist.name' => 'Bob Marley'
  'liner_notes.notes' => { 'like','%some text%' },},{
  join     => [qw/ artist liner_notes /],order_by => [qw/ artist.name /],}
);

DBIx cookbook说这是将生成的sql:

# Equivalent SQL:
# SELECT cd.*,artist.*,liner_notes.* FROM cd
# JOIN artist ON cd.artist = artist.id
# JOIN liner_notes ON cd.id = liner_notes.cd
# WHERE artist.name = 'Bob Marley'
# ORDER BY artist.name

但是从菜谱的其余部分开始,我一直认为查询只会选择cd.*,除非当然使用prefetch是这样的:

my $rs = $schema->resultset('CD')->search(
{
  'artist.name' => 'Bob Marley'
  'liner_notes.notes' => { 'like',prefetch => [qw/ artist liner_notes/],}
);

以下是让我相信这一点的陈述:

[Prefetch] allows you to fetch results from related tables in advance

任何人都可以向我解释我在这里缺少的东西吗?或不?非常感谢!

解决方法

等效SQL与菜谱的 previous section相矛盾,看起来像是一个错误.

在执行查询并应用过滤器和排序条件时,Join将使用连接表中的列,但它不会返回连接表的列.这意味着如果您执行$cd-> artist-> name,那么它将需要它来做一个额外的SELECT艺术家.* FROM artist WHERE artist.id =?每次打电话给那个陈述时都要得到艺术家的名字.

预取用于从预取表中选择所有列.在实际需要这些列时使用预取更有效,例如:所以你可以做$cd-> artist-> name而不需要它来做额外的查询.但是,如果您不需要这些列,那么加载该数据会产生不必要的性能损失.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读