[Tex/LaTex] Refsection and \includeonly warning

biberbiblatexincludesubdividing

I'm using biblatex with a biber backend to create a cumulative bibliography, subdivided by chapter. My (simplified) main file (main.tex) is:

\documentclass{book}

\usepackage[refsection=chapter, backend=biber]{biblatex}
\defbibheading{bibbook}[\bibname]{\chapter{#1}}
\defbibheading{subbib}[\refname\space\chaptername\space%
  \ref*{refsection:\therefsection}]{%
  \setcounter{secnumdepth}{0}%
  \section{#1}}
\addbibresource{biblatex-examples.bib}

\usepackage{hyperref}

\includeonly{bar}

\begin{document}

\mainmatter
  \include{foo}
  \include{bar}

\backmatter
  \printbibheading[heading=bibbook]
  \bibbysection[heading=subbib]

\end{document}

foo.tex is:

\chapter{Foo}
\label{cha:foo}
\nocite{cms}

and bar.tex is:

\chapter{Bar}
\ref{cha:foo}
\nocite{glashow}

According to this answer the benefit of using \include is that

"There will be a filename.aux file which contains all counter values,
like page and chapter numbers etc., at the begin of the filename. This
way the file can be compiled alone but still has the correct page and
chapter etc. numbers. Such part aux files are read by the main aux
file".

I expect the refsection counter to behave the same way. However when using \includeonly{some chapter} I get the following warning:

LaTeX Warning: Label `refsection:01' multiply defined.
LaTeX Warning: There were multiply-defined labels.

If I remove the includeonly command then the warning disappears but is there a way to avoid that warning when using the includeonly command?
Apparently the only way to eliminate the warning is by deleting the aux files of the chapters (not the main file) after each compilation. However in that way counter values are lost.

I know this is just a warning, not an error, and will not be an issue in the final (full) document. However I would like to understand why the warning appears and if possible to eliminate it.

EDIT: Before the bounty ends I want to make clear that I can tell my text editor (vim) not to show the warning. As I said before, what I really want to know why the warning appears when one of the advantages of using include is that it stores counter values.

Best Answer

From my testing, starting with a clean directory (no .aux files) it works fine with \includeonly. It's only a problem if you have a foo.aux hanging around from a previous run which created it (presumably without the \includeonly) and then you try to run with \includeonly - this seems to pick up and read the foo.aux which contains counters the same as in bar.aux. This makes sense as when you are effectively only including bar.aux by using \includeonly, this would get counter "01" but if you included both, foo.aux would have this. If you don't delete your .aux files between runs with different \includeonly settings, it's natural you will get conflicts because you have old .aux files around.

Related Question