SAN FRANCISCO — Buster Posey came out of surgery a couple of hours before the Giants began their final series of the season with the Diamondbacks. One of Arizona’s most important players believes Posey will be back to his old self when the teams take the same field for the first time next year.

Nick Ahmed, the Diamondbacks’ shortstop, underwent the same hip procedure two years ago and was operated on by the same doctor. Ahmed hit 14 homers in parts of three seasons before having his right hip repaired. Two years later, he has 16 in 124 games.

“I know what he was going through,” Ahmed said of Posey. “I’m sure that his power, unfortunately for us, is going to come back just fine.”

Ahmed’s surgery, also performed by Dr. Mark Phillipon in Vail, Colorado, was actually more complicated than Posey’s. He had his right labrum repaired, as Posey did, but also needed a microfracture procedure. That is relatively rare in the hip. Ahmed had surgery the final week of August in 2016.

“It was the same doctor and he did a great job with me,” Ahmed said. “I was back playing at six months. All the reports and information they gave me was that upwards of 50-60 percent of people who had the procedure I had would never come back and play again, but I’ve ended up playing better than I ever have, and I’m sure he will, too.”

Ahmed didn’t fully break through until he was given everyday time at short this season, and he could now stand as Brandon Crawford’s greatest competition in the Gold Glove race. His glove was always his calling card, but this season Ahmed has a .736 OPS and is slugging .439.

Posey slugged .382 before being shut down, with just five homers. Last week, he discussed being hampered by hip discomfort throughout the season.

“I just tried to make adjustments,” Posey said. “Occasionally, I’d alter some swing mechanics to feel like I can clear and not get stuck. Some days are better than others and I feel more like I’m used to feeling. Other days, I feel more locked up. Hopefully, I get this done and feel more of a consistent feeling.”

Ahmed outlined a similar process when discussing his injury-plagued 2016 season.

“Every day in the cage it was a battle to try to find a swing that essentially didn’t cause pain,” he said. “It’s really tough when you don’t have your legs underneath you and feel like you can’t load with your hips. You start swinging more with your upper body, and (Posey) is still such a good hitter that he’s able to do it, and at a clip where, while he wasn’t hitting the ball out of the ballpark, he was still getting his hits.”

Posey will return to the Bay Area on Thursday and is expected to miss six-to-eight months. The Giants are seven months away from opening day, but Posey and team officials are confident that he will not miss time in 2019. The rehab process has already started. Ahmed said he was put on a stationary bike two hours after he woke up from surgery in order to get his lower body moving, and manager Bruce Bochy said Posey has already started to move around.

Because of the microfracture element, Ahmed was off his feet for nine weeks, as doctors didn’t want him putting weight on his hip. Posey won’t have to deal with that, but preparing to catch is more complicated than rehabbing for any other position.

Ahmed has come back from his surgery as one of the league’s best shortstops. He expects Posey to return to being the hitter who has 15 career homers against the Diamondbacks.

“I felt even better when I came back, honestly,” he said. “I rehabbed it really aggressively. I came back strong and explosive and felt good.”