wordpress 中,何谓 parent query ?何谓 first_order_clause?

moliu 2015-11-19 04:54:06
wordpress 的 taxonomy.php 源码中,有 
function find_compatible_table_alias( $clause, $parent_query )
参数说明:
@param array $clause Query clause.
@param array $parent_query Parent query of $clause.
@return string|false Table alias if found, otherwise false
困惑我好久的问题是:何谓 parent query ?请教达人。
 附:源码
     protected function find_compatible_table_alias( $clause, $parent_query ) {
1164 $alias = false;
1165
1166 // Sanity check. Only IN queries use the JOIN syntax .
1167 if ( ! isset( $clause['operator'] ) || 'IN' !== $clause['operator'] ) {
1168 return $alias;
1169 }
1170
1171 // Since we're only checking IN queries, we're only concerned with OR relations.
1172 if ( ! isset( $parent_query['relation'] ) || 'OR' !== $parent_query['relation'] ) {
1173 return $alias;
1174 }
1175
1176 $compatible_operators = array( 'IN' );
1177
1178 foreach ( $parent_query as $sibling ) {
1179 if ( ! is_array( $sibling ) || ! $this->is_first_order_clause( $sibling ) ) {
1180 continue;
1181 }
1182
1183 if ( empty( $sibling['alias'] ) || empty( $sibling['operator'] ) ) {
1184 continue;
1185 }
1186
1187 // The sibling must both have compatible operator to share its alias.
1188 if ( in_array( strtoupper( $sibling['operator'] ), $compatible_operators ) ) {
1189 $alias = $sibling['alias'];
1190 break;
1191 }
1192 }
1193
1194 return $alias;
1195 }
  
  何谓 first_order_clause?
Determine whether a clause is first-order
   protected static function is_first_order_clause( $query ) {
return is_array( $query ) && ( empty( $query ) || array_key_exists( 'terms', $query ) || array_key_exists( 'taxonomy', $query ) || array_key_exists( 'include_children', $query ) || array_key_exists( 'field', $query ) || array_key_exists( 'operator', $query ) );
}
请教达人。
...全文
76 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
moliu 2015-11-21
$clause, $parent_query  和 nested query 嵌套查询相对应的  在wordpress 里,parent query 到底是哪些?有些迷糊
回复
xuzuning 2015-11-20
$parent_query Parent query of $clause 父查询子句 find_compatible_table_alias 查找兼容表别名 对于具体解释,你就不能找个中文的教程看看吗?
回复
moliu 2015-11-20
  关于函数 find_compatible_table_alias( $clause, $parent_query ) 有这样的 说明,哪位达人解释一下?谢谢 Identify an existing table alias that is compatible with the current query clause. * * We avoid unnecessary table joins by allowing each clause to look for * an existing table alias that is compatible with the query that it * needs to perform. * * An existing alias is compatible if (a) it is a sibling of `$clause` * (ie, it's under the scope of the same relation), and (b) the combination * of operator and relation between the clauses allows for a shared table * join. In the case of WP_Tax_Query, this only applies to 'IN' * clauses that are connected by the relation 'OR'.
回复
moliu 2015-11-19
$terms = implode( ",", $query['terms'] ); $terms = $wpdb->get_col( " SELECT $wpdb->term_taxonomy.$resulting_field FROM $wpdb->term_taxonomy INNER JOIN $wpdb->terms USING (term_id) WHERE taxonomy = '{$query['taxonomy']}' AND $wpdb->terms.{$query['field']} IN ($terms) 在 transform_query( &$query, $resulting_field ) 中,有上面的代码。能否以此为例讲一下?
回复
相关推荐
发帖
PHP
创建于2008-08-27

1.9w+

社区成员

“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
申请成为版主
帖子事件
创建了帖子
2015-11-19 04:54
社区公告
暂无公告