“The effect is marginal,” Mr. Muzzio said, adding that there were exceptions like the 1990 election of Mayor David N. Dinkins, a Democrat, in which Local 1199, the health care workers union now known as 1199 S.E.I.U., played a big role.

Four years ago, Mr. Appelbaum’s union, which has roughly 45,000 members in New York City, also came out with an early endorsement in the Democratic primary contest — in support of Christine C. Quinn, Mr. de Blasio’s rival who was then seen as the front-runner. At the time, Mr. Appelbaum cited her “electability.” The sanitation workers also endorsed Ms. Quinn. After her loss, both unions backed Mr. de Blasio in the general election.

Sitting in his Midtown Manhattan office overlooking Seventh Avenue and the Macy’s flagship store, where many of the union’s members work, Mr. Appelbaum said this month that he was “trying to send a message” with an early endorsement this time around that Mr. de Blasio “has earned our support” through his actions on behalf of working people.

Despite some grumbling among the city’s unions, most labor leaders have been cheered by Mr. de Blasio’s efforts on their behalf. He signed contracts with nearly every municipal union quickly after taking office, and threw the doors of City Hall open to their concerns after two decades of arms-length relations under the former mayors Michael R. Bloomberg, a Republican turned political independent, and Rudolph W. Giuliani, a Republican.

On Monday afternoon, Mr. de Blasio appeared before a crowded, hot and rowdy room full of sanitation workers. “This, gentlemen, is a union-friendly mayor,” Harry Nespoli, president of the Uniformed Sanitationmen’s Association, told them before leading a chant of “four more years.” Mr. de Blasio reached a deal on the contract for the city’s roughly 6,000 sanitation workers last year.

Mr. de Blasio, in his remarks, celebrated the workers and offered a kind of slogan for his re-election bid — “a city for everyone, and a city where everyone has a shot” — as he framed the moment as an opening marker in a Democratic campaign that, in Mr. Trump, has a ready-made foil.