[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-detail-84862-en":3,"doc-seo-84862-105":29,"detail-sidebar-cat-0-en-105":91},{"code":4,"msg":5,"data":6},0,"success",{"doc_id":7,"user_id":8,"nickname":9,"user_avatar":10,"doc_module":4,"category_id":11,"category_name":12,"doc_title":13,"doc_description":14,"doc_content":15,"file_id":16,"file_url":17,"file_type":18,"file_size":19,"view_count":20,"is_deleted":4,"is_public":20,"is_downloadable":20,"audit_status":20,"page_count":21,"language":22,"language_code":23,"site_id":24,"html_lang":23,"table_of_contents":25,"faqs":26,"seo_title":13,"seo_description":14,"update_tm":27,"read_time":28},84862,8796095461564,"Liam","https://ap-avatar.wpscdn.com/davatar_155a257f0dc6eb9ab79c44ca47cae57d",8,"Research & Report","BaCon: Efficient Batch Processing of Counting Queries","Counting queries are central to database optimization and learning-based cardinality estimation, where training requires large sets of query-count pairs. Creating this data by executing massive batches of counting queries is costly. BaCon delivers efficient batch evaluation of counting queries on top of existing database systems, without altering their internals. It combines factorized databases with workload-aware domain quantization to use compact structures instead of materializing large joins. Implemented as a client-side PostgreSQL application with a lightweight C-language UDF, BaCon achieves 2×–178× speedups across diverse workloads and makes learned CE training and maintenance substantially more practical.","BaCon: Efficient Batch Processing of Counting Queries  \nYuxi Liu  \nDuke University [yuxi.liu@duke.edu](yuxi.liu@duke.edu)  \nPankaj K. Agarwal  \nDuke University [pankaj@cs.duke.edu](pankaj@cs.duke.edu)  \nXiao Hu University of Waterloo [xiaohu@uwaterloo.ca](xiaohu@uwaterloo.ca)  \nJun Yang  \nDuke University [junyang@cs.duke.edu](junyang@cs.duke.edu)  \narXiv :2607 .05832v 1 [ cs .DB] 7 Jul 2026  \nABSTRACT  \nCounting queries are ubiquitous in database systems, particularly for driving internal system optimization. Learned models for cardinality estimation rely heavily on large-scale training data, yet generating such data by executing massive batches of counting queries is expensive. We propose BaCon, an efficient algorithm for batch evaluation of counting queries on top of a database system, without modifying its internals. BaCon integrates the idea of factorized databases with a workload-aware domain quantization strategy, allowing it to evaluate batches of counting queries using compact data structures rather than materializing massive join results. BaCon’s design is compatible with most database management system, and we have implemented it as a client-side application on PostgreSQL with a lightweight C-language UDF (user-defined function) . This implementation delivers speedups between 2× and 178× over baselines and good performance across various workloads, making training and maintenance of learned cardinality estimation models significantly more practical.  \nPVLDB Reference Format:  \nYuxi Liu, Xiao Hu, Pankaj K. Agarwal, and Jun Yang. BaCon: Efficient Batch Processing of Counting Queries. PVLDB, 19(9): 2508-2521, 2026 .  \ndoi:10.14778/3819518.3819567  \nPVLDB Artifact Availability:  \nThe source code, data, and/or other artifacts have been made available at [https://github.com/louisja1/bacon](https://github.com/louisja1/bacon).  \n1 INTRODUCTION  \nBatches of counting queries are not only useful in their own right for database applications, but also frequently serve to collect basic statistics from data for monitoring and optimization. With the growing popularity of learned query optimization [12, 46, 47, 82] in recent years, an interesting workload has emerged: collecting training data for learned cardinality estimation (CE) [13, 27, 29, 40, 50, 51, 58, 60, 71] . CE is a critical component of query optimization, as its accuracy directly impacts the quality of query execution plans [35, 61] . In these workloads, queries typically involve joinsand selections over base tables but report only the final counts ofthe result sets. These query-count pairs are subsequently used to train  \nThis work is licensed under the Creative Commons BY-NC-ND 4.0 International License. Visit [https://creativecommons.org/licenses/by-nc-nd/4.0/ to view a copy of](https://creativecommons.org/licenses/by-nc-nd/4.0/ to view a copy of)[ ](https://creativecommons.org/licenses/by-nc-nd/4.0/ to view a copy of)[this license. For any use beyond those covered by this license](this license. For any use beyond those covered by this license), [obtain permission by](obtain permission by)[emailing info@vldb.org. Copyright](emailing info@vldb.org. Copyright) is held by the owner/author(s). Publication rights licensed to the VLDB Endowment.  \nProceedings of the VLDB Endowment, Vol. 19, No. 9 ISSN 2150-8097 .  \ndoi:10.14778/3819518.3819567  \nCE models. Such queries may be derived from past workloads or synthesized specifically for training. While the number of distinct join patterns is naturally limited by the database schema, the queries themselves additionally contain a variety of selection conditions, targeting different attributes with varying constants. Beyond simple equality comparisons, many conditions involve inequality or range predicates. Table 1 summarizes nine public query workloads widely used in CE research for training and evaluation. These workloads span three commonly studied benchmark databases—IMDB [35], STATS [18] and DSB [10]—and capture a broad ra","cbCaipHUkDLwnz4G","https://ap.wps.com/l/cbCaipHUkDLwnz4G","pdf",3643553,1,22,"English","en",105,"# Introduction\n# Background and Motivation\n## Counting Queries for Learned Cardinality Estimation\n## Why Batch Execution Is Expensive\n# BaCon Overview\n## Core Idea and Design Goals\n## Implementation Approach","[{\"question\":\"What problem does BaCon address?\",\"answer\":\"BaCon targets the high cost of generating training data for learned cardinality estimation when it relies on executing large batches of counting queries to obtain query-count pairs.\"},{\"question\":\"How does BaCon evaluate counting-query batches without changing the database internals?\",\"answer\":\"BaCon evaluates batches on top of a database system by using factorized-database ideas and workload-aware domain quantization to compute per-query counts via compact data structures instead of materializing massive join results.\"},{\"question\":\"How is BaCon implemented and what performance does it achieve?\",\"answer\":\"BaCon is implemented as a client-side application on PostgreSQL with a lightweight C-language UDF, achieving speedups ranging from 2× to 178× over baseline methods across different workloads.\"}]",1784198890,55,{"code":4,"msg":30,"data":31},"ok",{"site_id":24,"language":23,"slug":32,"title":13,"keywords":33,"description":14,"schema_data":34,"social_meta":86,"head_meta":88,"extra_data":90,"updated_unix":27},"bacon-efficient-batch-processing-of-counting-queries","",{"@graph":35,"@context":85},[36,53,68],{"@type":37,"itemListElement":38},"BreadcrumbList",[39,43,47,50],{"item":40,"name":41,"@type":42,"position":20},"https://docshare.wps.com","Home","ListItem",{"item":44,"name":45,"@type":42,"position":46},"https://docshare.wps.com/document/","Document",2,{"item":48,"name":12,"@type":42,"position":49},"https://docshare.wps.com/document/research-report/",3,{"item":51,"name":13,"@type":42,"position":52},"https://docshare.wps.com/document/bacon-efficient-batch-processing-of-counting-queries/84862/",4,{"url":51,"name":13,"@type":54,"author":55,"headline":13,"publisher":57,"fileFormat":60,"inLanguage":23,"description":14,"dateModified":61,"datePublished":62,"encodingFormat":60,"isAccessibleForFree":63,"interactionStatistic":64},"DigitalDocument",{"name":9,"@type":56},"Person",{"url":40,"name":58,"@type":59},"DocShare","Organization","application/pdf","2026-07-17","2026-07-16",true,{"@type":65,"interactionType":66,"userInteractionCount":20},"InteractionCounter",{"@type":67},"ViewAction",{"@type":69,"mainEntity":70},"FAQPage",[71,77,81],{"name":72,"@type":73,"acceptedAnswer":74},"What problem does BaCon address?","Question",{"text":75,"@type":76},"BaCon targets the high cost of generating training data for learned cardinality estimation when it relies on executing large batches of counting queries to obtain query-count pairs.","Answer",{"name":78,"@type":73,"acceptedAnswer":79},"How does BaCon evaluate counting-query batches without changing the database internals?",{"text":80,"@type":76},"BaCon evaluates batches on top of a database system by using factorized-database ideas and workload-aware domain quantization to compute per-query counts via compact data structures instead of materializing massive join results.",{"name":82,"@type":73,"acceptedAnswer":83},"How is BaCon implemented and what performance does it achieve?",{"text":84,"@type":76},"BaCon is implemented as a client-side application on PostgreSQL with a lightweight C-language UDF, achieving speedups ranging from 2× to 178× over baseline methods across different workloads.","https://schema.org",{"og:url":51,"og:type":87,"og:title":13,"og:site_name":58,"og:description":14},"article",{"robots":89,"canonical":51},"index,follow",{"doc_id":7,"site_id":24},{"code":4,"msg":5,"data":92},[93,97,101,105,110,115,120,123,128,131,135],{"id":20,"doc_module":4,"doc_module_name":45,"category_name":94,"show_sort_weight":95,"slug":96},"Story & Novel",90,"story-novel",{"id":46,"doc_module":4,"doc_module_name":45,"category_name":98,"show_sort_weight":99,"slug":100},"Literature",80,"literature",{"id":52,"doc_module":4,"doc_module_name":45,"category_name":102,"show_sort_weight":103,"slug":104},"Exam",70,"exam",{"id":106,"doc_module":4,"doc_module_name":45,"category_name":107,"show_sort_weight":108,"slug":109},5,"Comic",60,"comic",{"id":111,"doc_module":4,"doc_module_name":45,"category_name":112,"show_sort_weight":113,"slug":114},6,"Technology",50,"technology",{"id":116,"doc_module":4,"doc_module_name":45,"category_name":117,"show_sort_weight":118,"slug":119},7,"Healthcare",40,"healthcare",{"id":11,"doc_module":4,"doc_module_name":45,"category_name":12,"show_sort_weight":121,"slug":122},30,"research-report",{"id":124,"doc_module":4,"doc_module_name":45,"category_name":125,"show_sort_weight":126,"slug":127},9,"Religion & Spirituality",20,"religion-spirituality",{"id":126,"doc_module":4,"doc_module_name":45,"category_name":129,"show_sort_weight":126,"slug":130},"World Cup","world-cup",{"id":132,"doc_module":4,"doc_module_name":45,"category_name":133,"show_sort_weight":132,"slug":134},10,"Lifestyle","lifestyle",{"id":136,"doc_module":4,"doc_module_name":45,"category_name":137,"show_sort_weight":106,"slug":138},19,"General","general"]